How to create a new file from existing file using grep command in unix.


Consider i have a file named as main.log having following contents:
Today is Monday
Today is Monday
Today is Tuesday
Today is Monday
Today is Wednesday
Today is Monday
Today is Thursday

And now i want to make a new file which contains line having “Monday” .
Command is :
grep “Monday” main.log > monday.log

Now if in case you want to append to the same file then:
grep “Monday” main.log >> monday.log

The single > is used to create a new file and >> is used to append the existing file.