fgrep pipes
Hi,
I have six files and I need to fetch the lines that are common among all of these files. Lets say I have 1.txt, 2.txt, 3.txt....6.txt. I was trying the following command. $ fgrep -f 1.txt 2.txt | fgrep 3.txt | fgrep 4.txt .... | fgrep 6.txt > Common_among_all.txt But this is not working :( Do anyone have any idea how to do this,, I will really appreciate your comments....Many thanks in advance :) I did this using cat and uniq: $ cat *.txt | sort | uniq -c | awk '{if ($1 ==6 ) print $0}' |
Note that it works if identical lines are present only one time for each file
(eg it might fail if in one file, same line is present 6 times) Based on this assumption, this perl line might also work: Code:
perl -ne '{print if ++$s{$_}==6}' *.txt |
Quote:
Code:
fgrep -xf 1.txt 2.txt | fgrep -xf - 3.txt | fgrep -xf - 4.txt ... | fgrep -xf - 6.txt |
u can use this....
grep -hf 1.txt 2.txt | grep -hf 3.txt | grep -hf 4.txt | grep -hf 5.txt | grep -hf 6.txt> common.txt -f, --file=FILE obtain PATTERN from FILE -h, --no-filename suppress the prefixing filename on output also you can use if needed : -w, --word-regexp force PATTERN to match only whole words -x, --line-regexp force PATTERN to match only whole lines hope this helps !! |
Thank you all,, your suggestions are really helpful..many thanks :)
|
All times are GMT -5. The time now is 09:30 AM. |