3

For example:

hello1.jpg
hello2.jpg
hello3.jpg

I would like to edit it so that it is like this:

hello1.jpg 0
hello2.jpg 0
hello3.jpg 0

I have tried:

sed -i '/(hello*)/ s/$/ 0/' hello.txt
perl -ipe 's/$/ 0/ if /hello/' hello.txt
sed -i '/^hello*/ s/$/ 0/' hello.txt

3 Answers 3

6

Your first approach was almost correct, aside from the fact that the parentheses (which aren't needed) were being interpreted literally:

$ sed '/hello/ s/$/ 0/' file
hello1.jpg 0
hello2.jpg 0
hello3.jpg 0
Sign up to request clarification or add additional context in comments.

Comments

3

You don't need the globs or other * uses in your sed command. The following works for me:

sed -e '/hello/ s/$/ 0/' hello.txt

and you can use the -i (with GNU) once you're sure that works for you

Comments

1
awk '/hello/{print $0" "0}' filename

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.