Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep maint & product from files

Status
Not open for further replies.

deepa20

Programmer
Sep 19, 2006
12
DE
I am newbie for this site and unix . I am writing shell script to grep maint and product from different files

the files are stored in sub directories
i have to grep filename maint product
 
Welcome. Can you give a sample of the files you're working with - with details changed to protect the innocent if appropriate!

I don't mind people who aren't what they seem. I just wish they'd make their mind up.

Alan Bennett.
 
thanks for ur reply . the maint name and product name are in Header of file
# $maint$ : dips
# $product$ : test
The files are stored in subdirectories with etn *.exp.

i worte the script
find /users/testsuite/SiCat.Tests/daily/DB/ -name \*.exp |xargs grep "maint" |"product"

it is greping only maint name , i want to grep product name too .

i need output in ths format
/users/testsuite/Sicat.tests/daily/DB/area/area0.exp $maint$ : dips $product$ : test
 
Hi

Your evident problem is the wrong use of pipe ( | ) :
Code:
grep "maint" |"product"   [gray]# grep for "main" then pipe the results to "product"[/gray]
grep "maint\|product"     [gray]# grep for "main" or "product"[/gray]
Because the grouping and removing of the hash ( # ) is hard and ugly this way, I suffest using [tt]awk[/tt] :
Code:
find /users/testsuite/SiCat.Tests/daily/DB/ -name \*.exp | xargs awk '{sub(/^# */,"")}/maint/{m=$0}/product/{print FILENAME,$0,m}'
Note, that while you had no protection against finding multiple mathing lines in one file, I did not implemented neither.

Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
it is not working giving error
awk: illegal statement near line 1
 
i tried all option and in our system awak and gawk both are installed .
awk: syntax error near line 1
awk: illegal statement near line 1

this error i am getting pls do help
 
Have you tried this ?
find /users/testsuite/SiCat.Tests/daily/DB/ -name \*.exp |xargs grep -e "maint" -e "product"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
yeah i tried this also . it takes only giving maint output.
any other soultions
i tried egrep also .. i think sed or awk will be best soultion but need help to write script
 
#!/usr/local/bin/gawk

find /users/testsuite/SiCat.Tests/daily/DB/ -name \*.exp | xargs gawk 'BEGIN{m="
not found ";prod=" not found "}/maint/{m=$3}/product/{prod=$3}END{print FILENAME
,m,prod}'


This is working .. i changed the script like this ..

Thanks for help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top