Monday, December 16, 2013

Unix pattern serching using grep, search location should be limited to first 5 characters of every record(every line) in the file

www.unixbabuforum.inI need a help on one unix script. 
I need to match pattern for first 5 characters of every line of a file using grep.If it is matching, I need to redirect the full line of the matching row. 
My requirement is like this. 
Refernce file for matching pattern

www.unixbabuforum.inTry this 

rm output 
touch output 
while read pattern 
if [[ `grep -c "^$pattern" inputfile` -gt 0 ]]; then 
grep "^$pattern" file2 >> output 
done < patternfile 


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM