Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sed expression fixed #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mchangrh
Copy link

The sed expression on bash matches with almost every character, creating text files full of Me: Friend:Me: Friend. Enclosing it in single quotes allows sed to process the 1 as is and includes the escape character |

Copy link

@tagatac tagatac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes are not the problem here. Rather, you want to remove the g so that the substitution only applies to the first match per line instead of every match.

@@ -37,13 +37,13 @@ for line in $(select_rows "select distinct guid from chat;" ); do
select is_from_me,text, datetime((date/1000000000) + strftime('%s', '2001-01-01 00:00:00'), 'unixepoch', 'localtime') as date from message where handle_id=(
select handle_id from chat_handle_join where chat_id=(
select ROWID from chat where guid='$line')
)" | sed 's/1\|/Me: /g;s/0\|/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
)" | sed 's/'1\|'/Me: /g;s/'0\|'/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)" | sed 's/'1\|'/Me: /g;s/'0\|'/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
)" | sed 's/1\|/Me: /;s/0\|/Friend: /' > $BACKUP_DIR/$contactNumber/$line.txt

else
select_rows "
select is_from_me,text, datetime(date + strftime('%s', '2001-01-01 00:00:00'), 'unixepoch', 'localtime') as date from message where handle_id=(
select handle_id from chat_handle_join where chat_id=(
select ROWID from chat where guid='$line')
)" | sed 's/1\|/Me: /g;s/0\|/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
)" | sed 's/'1\|'/Me: /g;s/'0\|'/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)" | sed 's/'1\|'/Me: /g;s/'0\|'/Friend: /g' > $BACKUP_DIR/$contactNumber/$line.txt
)" | sed 's/1\|/Me: /;s/0\|/Friend: /' > $BACKUP_DIR/$contactNumber/$line.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants