How to append text in the beginning of each line using sed

<AppendNhere> A H W C
<AppendNhere> A H W C
<AppendNhere> A H W C

Sed '/^/ i N' filename

I tried appending N using this, but it's appending N to the beginning of new lines and not at the start of existing rows.

2 Answers

First, you need to understand "quoting" (see man bash) and regular expressions (man 7 regex) and use sed's (man sed "substitute" command.

sed -e 's/^/N/' filename

You can do this with

sed -e "s/^\(.*\)/N \1/" filename

This inserts the string N at the beginning of the line (^).

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like