0

I'm looking for the string SUCCESS into the file_1 & file_2 which in this case looks for the string and prints it based on whether its there on only file_1 or on both file_1 and file_2 while I'm looking it to print only once either its on both the file of one. How that can be done?

$ grep SUCCESS file_1  file_2

Result:

file_1:Host fox_01 is SUCCESS
file_2:Host fox_02 is SUCCESS
file_2:Host fox_01 is SUCCESS

I'm open to any advice or solution, not necessarily grep.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
krock1516
  • 343

2 Answers2

1

Use grep -h to not print the file names, and then awk to suppress duplicate lines:

grep -h SUCCESS file_1  file_2 | awk '!seen[$0]++'

or if you wish to sort:

grep -h SUCCESS file_1  file_2 | sort -u
pLumo
  • 22,565
1

Try this,

awk '/SUCCESS/ && !a[$0]++' file_1 file_2

Host fox_01 is SUCCESS
Host fox_02 is SUCCESS

will check for the keyword "SUCCESS" and ignores duplicate

Siva
  • 9,077