achmad irfan
achmad irfan

Reputation: 55

Delete text in file using bash script in linux

I want to create an script that deletes few lines from a file containing the following text

you.com
me.ac.id
burger.co.us
manheal.com

If i want to delete this:

burger.co.us

How is the syntax in shell programming??

Upvotes: 2

Views: 21684

Answers (1)

Brian Agnew
Brian Agnew

Reputation: 272277

sed "/burger.co.us/d" < inputfile > outputfile

will match and delete that line from inputfile and write to outputfile using redirection.

Note that you can't read your input and write to the same file using the above. Instead use the -i field to specify replacement in-place.

See here for more about sed.

Upvotes: 13

Related Questions