0

I have used the following command to get unique list of each name from my file

grep -oP "name_\w*" file_copy.txt | sort |uniq > list.txt
FILE=list.txt
while read line; do
     cat file_copy.txt | grep "$line" | wc -l 
     cat file_copy.txt | grep $line | grep "name" | grep $line+1 -v | wc -l

Last command is not running the way i expected


list.txt files like below:
USA
Russia
Japan

file_copy.txt
USA Russia Russia Russia Japan
Japan Japan USA USA Russia
Japan Japan USA USA Russia
Japan Russia USA USA Russia

  • 2
    would be a good idea to add sample input and expected output as well – Sundeep Nov 23 '16 at 16:12
  • @Sundeep I have two files one is list_txt where I have some unique names like a,b,c etc and second file which is file_copy.txt where i would like to search and count these names to create a venn. And I want combinations of two and invert-match(-v) for third. – new bie Nov 23 '16 at 16:27
  • that is not clear, at least to me.. what I would suggest is create sample files for list_txt, file_copy.txt and add complete expected output for that to question... – Sundeep Nov 23 '16 at 16:31
1

Replace last line to:

grep -c -e "$line" -e "name" -e $((line+1))

You can define more condition with parameter -e, and wc is useless, grep can count matches with -c

0

For a given input file:

a
b
c
d
e
f
g

If you want to get a count for any lines matching, say, e and b:

$ grep -c -e 'e' -e 'b'
2
  • Thank you @DopeGhoti, I would like do invert-match(-v) for one of the character and check the overlapping to create a Venn. So the Idea is to match these names in another files to count overlapping numbers – new bie Nov 23 '16 at 16:22
  • You might want to look into comm. – DopeGhoti Nov 23 '16 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.