System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

find two words repeat in file

 
SOLVED
Go to solution
Jairo Campana
Trusted Contributor

find two words repeat in file

Hi , I have a file with two word HostGroupName and Platform, need extract the two word in file Test

the words are repeated in different line numbers

using for, awk no work :
for var in "HostGroupName" "Parnert"

nawk '/"$var"/ {getline; getline; getline; getline; getline; getline; getline; getline; getline; getline; getline; getline x; getline y ; print x; print y}' Test


cat Test

Micro Program Revision : 165C/R
Array Unit Type : DF600
Serial Number : 68017811
MappingMode = ON
Reset/LIP Mode(Signal) = OFF
Reset/LIP Mode(Process) = OFF
LIP Port All Reset Mode = OFF
Read Frame Min 128 Byte Mode = OFF
HostGroupNumber = 0
HostGroupName = "jojo"
Platform = not specified
Alternate Path = not specified
Failover = not specified
Additional Parameters

......
......

MappingMode = ON
Reset/LIP Mode(Signal) = OFF
Reset/LIP Mode(Process) = OFF
LIP Port All Reset Mode = OFF
Read Frame Min 128 Byte Mode = OFF
HostGroupNumber = 0
HostGroupName = "jajaja"
Platform = not specified
Alternate Path = not specified
Failover = not specified
Additional Parameters

result that I need to obtain
HostGroupName = "jajaja"
Platform = not specified
HostGroupName = "jojo"
Platform = not specified
legionx
5 REPLIES
Patrick Wallek
Honored Contributor

Re: find two words repeat in file

Perhaps I don't understand completely, but wouldn't this work?

# grep -e HostGroupName -e Platform Test

Tingli
Esteemed Contributor
Solution

Re: find two words repeat in file

egrep "HostGroupName|Platform" Test
Bob E Campbell
Honored Contributor

Re: find two words repeat in file

# sed -e "s/=.*$//" Test |\
grep -v -e ^$ |\
sort |\
uniq -c |\
grep -v -e "^ 1 " |\
while read CNT DATA
do
grep "${DATA}" Test
done
Additional Parameters
Additional Parameters
Alternate Path = not specified
Alternate Path = not specified
Failover = not specified
Failover = not specified
HostGroupName = "jojo"
HostGroupName = "jajaja"
HostGroupNumber = 0
HostGroupNumber = 0
LIP Port All Reset Mode = OFF
LIP Port All Reset Mode = OFF
MappingMode = ON
MappingMode = ON
Platform = not specified
Platform = not specified
Read Frame Min 128 Byte Mode = OFF
Read Frame Min 128 Byte Mode = OFF
Reset/LIP Mode(Process) = OFF
Reset/LIP Mode(Process) = OFF
Reset/LIP Mode(Signal) = OFF
Reset/LIP Mode(Signal) = OFF

Re: find two words repeat in file

You need to provide more details about what you want to extract from your file.

You can't put $var in single quotes:
for var in "HostGroupName" "Parnert"; do
awk "/$var/"' {getline; getline; getline; getline; getline; getline; getline; getline; getline; getline; getline; getline x; getline y; print x; print y}' Test
done
Jairo Campana
Trusted Contributor

Re: find two words repeat in file

whith getline , can't put $var in single quotes:

this works ok , awk "/$var/"'
legionx