Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed: just trying to remove a substring

Tags:

I have a file with this content:

foo: bar1 foo: bar2 foo: bar3 foo: bar4 foo: bar5 

I want to remove the chains "foo: " so the file remains:

bar1 bar2 bar3 ... 

I'm trying it with:

$ sed 's/foo: /' file.txt 

but it says:

sed: -e expression #1, char 15: unterminated `s' command

Any help?

Javi

like image 559
user1077220 Avatar asked Dec 02 '11 13:12

user1077220


People also ask

What can I use instead of sed?

Alternatives to sed include the Unix utility awk , perl , and nearly any general purpose programming language.

What is 1d in sed?

$ sed -i '1d' filename. In the example, 1d essentially stands for first line deletion. Using a\ (“append”) can add lines to a file.

How do I delete a record using sed?

To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.


1 Answers

You need to:

$ sed -r 's/^foo: //' file.txt 
like image 148
aefxx Avatar answered Sep 23 '22 15:09

aefxx