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
This awk script will do the trick:
awk
awk '{a[NR]=$0}END{for(i=1;i<=NR;i++)print a[i] > "file"(a[i]~/bar/?2:1)}' file1
Outputs:
$ cat file1 bla foo bla bla aaa bla bla foo bla $ cat file2 bla bar bla bla bar bla