1

Move lines matching a pattern from one file to another

view story
linux-howto

http://stackoverflow.com – I want to move lines matching certain pattern from file1 to file2. Analogous to operation cut and paste from one file to another in windows Example let's say I want to cut all lines containg bar from file1 and paste it into newly created file2 Input: file1 bla foo bla bla bar bla bla aaa bla bla bar bla bla foo bla Desired output after processing: file1 bla foo bla bla aaa bla bla foo bla file2 bla bar bla bla bar bla What I have tried grep creates desired file2 but doesn't modify file1 grep 'bar' file1 > file2 sed -i modifies desired file1 but doesn't create file2 sed -i (HowTos)