Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINUX Shell commands cat and grep

Tags:

linux

shell

I am a windows user having basic idea about LINUX and i encountered this command:

cat countryInfo.txt | grep -v "^#" >countryInfo-n.txt

After some research i found that cat is for concatenation and grep is for regular exp search (don't know if i am right) but what will the above command result in (since both are combined together) ?

Thanks in Advance.

EDIT: I am asking this as i dont have linux installed. Else, i could test it.

like image 645
Vignesh T.V. Avatar asked Jun 06 '13 11:06

Vignesh T.V.


2 Answers

Short answer: it removes all lines starting with a # and stores the result in countryInfo-n.txt.

Long explanation:

cat countryInfo.txt reads the file countryInfo.txt and streams its content to standard output.

| connects the output of the left command with the input of the right command (so the right command can read what the left command prints).

grep -v "^#" returns all lines that do not (-v) match the regex ^# (which means: line starts with #).

Finally, >countryInfo-n.txt stores the output of grep into the specified file.

like image 156
DarkDust Avatar answered Sep 28 '22 08:09

DarkDust


It will remove all lines starting with # and put the output in countryInfo-n.txt

like image 25
shyam Avatar answered Sep 28 '22 10:09

shyam