LINUX cat and grep command line commands

I am a Windows user with a basic understanding of LINUX, and I came across this command:

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

After some research, I found that cat is for concatenation, and grep is for regularly looking for exp (I don't know if I'm right), but what will lead to this command (since both of them are combined together)?

Thanks at Advance.

EDIT: I am asking about this since I do not have linux. Else, I could check it out.

+4
source share
3 answers

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

Long explanation:

cat countryInfo.txt reads the cat countryInfo.txt file and passes its contents to standard output.

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

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

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

+8
source

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

+3
source

This command will remove lines starting with # from the countryInfo.txt file and put the output in the countryInfo-n.txt .

This command can also be written as

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

See Useless Use of Cat .

+3
source

Source: https://habr.com/ru/post/1484814/


All Articles