ureddy
1
Hi,
I want to print the lines from file1 which has the matching pattern from file2 in linux.
file1 data is below
-----------------
CACA|1234
CA|2345
file2 data is below
-----------------
CA
NC
TX
Now I want to print the lines from file1 for the values present in file2.
-
print the string which occurs more than once. In this case the out i need to get is CACA|1234
-
Print the string which occurs only once. in this case the output i need to get is CA|2345
can any one help me how to do this please
For starters
grep - o '[pattern]' file
prints just the pattern, nothing else -- GNU grep only, which normally is part of a Linux distribution.
ureddy
3
thanks for the reply. but i need to print the lines
PikK45
4
grep -f file2 file1
This will help you print lines from file1 that matches patterns in file2
awk -F"|" 'FNR==NR{a[$1];next}$1 in a' file2 file1
ureddy
6
hi,
there are two cases here.
- print the string which occurs more than once into seperate file
- Print the string which occurs only once into seperate file
so need to capture the output into seperate files.
the above solutions all are capturing either one or more occurences of string to a single file.