3

I though this was going to be a simple task but I am having some trouble with it.

Sample input

$ cat file.txt
Brown Potatoes with Cheese
Yellow Potatoes with Sugar and Cheese

I would like to use sed to remove everything after the string with

So the output would be

Brown Potatoes 
Yellow Potatoes 

I've tried this regex but it doesn't seem to work.

sed -i -e "s/with.*//g" file.txt

Where did I go wrong?

Sundeep
  • 19,273
  • 2
  • 19
  • 42
Tomáš Janulík
  • 39
  • 1
  • 1
  • 5

1 Answers1

4
mathb@Balu:~$ sed -i.bak 's/with.*//g' file.txt
mathb@Balu:~$ cat file.txt
Brown Potatoes

Yellow Potatoes
mathb@Balu:~$
mathB
  • 614
  • 8
  • 19