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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s