Link to home
Start Free TrialLog in
Avatar of malcolm_fitz
malcolm_fitz

asked on

Need for work, only a noob. need to search many files for a string "USER HELP", then drop down 1 line and search only next line..

Hi, I'm new to Linux and starting to learn it at work. I need to search many files for a string "USER HELP" if that exists, i need to check the next line down to see if it has "USERHELP=1" under neith it then if it does, pip to a file, have tried and am lost now..

all I have got to is:   find . -name "*4gl" | xargs grep "USER HELP" > results

but i think i need a loop..
Avatar of AgelmarJagad
AgelmarJagad

Have you tried that command without using xargs?  As in 'find . -name "*4gl" | grep "USER HELP" > results.  What is the exact problem that you are having?  Are you not getting output into the file?  Are you not getting the correct output?
Avatar of malcolm_fitz

ASKER

Ive got this so far:

find /home/malcolm/ -name "*4gl" | xargs grep -n -i --after-context=2 "USER HELP"  > /home/malcolm/workdir/aa

but I now need to check to see if 1 line under is not "USERHELP=1" then pip that line number and file to a file..  :)
If a file contains the first line, can you assume it also contains the second line too ?
I mean, if a file contains "USER HELP" can you assume that if the file contains the line "USERHELP" it will be
the following line ?

if yes, then use:

find . -name "*.4gl" -exec grep -e "USER HELP" -e "USERHELP=1" \; -print

Of course you will have to redirect some output to /dev/null if you just want filenames.
ASKER CERTIFIED SOLUTION
Avatar of AgelmarJagad
AgelmarJagad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, and by the way, the \ at the end of the first line of the command just signifies that the command continues on the next line, you can ignore it and just keep typing.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by AgelmarJagad
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

khkremer
EE Cleanup Volunteer