1833178 Members
2587 Online
110051 Solutions
New Discussion

Re: grep

 
SOLVED
Go to solution
panchpan
Regular Advisor

grep

I would like to grep for '-n' and '-N' and '-G' from many files. Please advice, how can it be done?
13 REPLIES 13
Luk Vandenbussche
Honored Contributor

Re: grep

In one directory

grep -n string *
Oviwan
Honored Contributor

Re: grep

cat yourfile | grep -E '\-[NnG]'
James R. Ferguson
Acclaimed Contributor
Solution

Re: grep

Hi:

# grep -e "-n" -e "-N" -e "-G" file1 file2 file3 ...

# grep -e "-n" -e "-N" -e "-G" /etc/*

# find /path -type f -exec grep -e "-n" -e "-N" -e "-G" {} \+

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: grep

No need to use egrep:
$ grep -e -n -e -N -e -G file1 file2 ...
panchpan
Regular Advisor

Re: grep

Here PK is a server name and db_cnt is a number e.g. 001. How can i grep within such files? Shell isnt able to understand correct value of $db_cnt

ssh $PK 'grep -e "-n" -e "-L" /global/pf/a\?\?\?\$'{db_cnt}'pst.pf' ;
Luk Vandenbussche
Honored Contributor

Re: grep

ssh $PK 'grep -e "-n" -e "-L" /global/pf/a\?\?\?\${db_cnt}pst.pf' ;
panchpan
Regular Advisor

Re: grep

Still same error:

+ ssh a0300001p2 grep -e "-n" -e "-L" /global/pf/a\?\?\?\${db_cnt}pst.pf

grep: can't open /global/pf/a???${db_cnt}pst.pf
Oviwan
Honored Contributor

Re: grep

without any quotes it works. and don't escape the $.

ssh $PK grep -e "-n" -e "-L" /global/pf/a\?\?\?${db_cnt}pst.pf
panchpan
Regular Advisor

Re: grep

still same error:

+ ssh a0300001p2 grep -e "-n" -e "-L" /global/pf/a\?\?\?\$db_cnt}pst.pf
grep: can't open /global/pf/a???$db_cnt}pst.pf
Oviwan
Honored Contributor

Re: grep

you have still escaped the dollar sign ($). hence the variable can't be resolved.

+ ssh a0300001p2 grep -e "-n" -e "-L" /global/pf/a\?\?\?\$db_cnt}pst.pf
grep: can't open /global/pf/a???$db_cnt}pst.pf

change it to this:

ssh $PK grep -e "-n" -e "-L" /global/pf/a\?\?\?${db_cnt}pst.pf
panchpan
Regular Advisor

Re: grep

+ ssh a0300001p2 grep -e "-n" -e "-L" /global/pf/a\?\?\?${db_cnt}pst.pf
grep: can't open /global/pf/a???pst.pf
Oviwan
Honored Contributor

Re: grep

that's why you don't have set your variable (db_cnt)

db_cnt=001 #anynumber of a file...

then execute it again!
Tor-Arne Nostdal
Trusted Contributor

Re: grep


Just a small observation...

Your missing a parantese in:
$db_cnt}pst.pf

I assume it should say:
${db_cnt}pst.pf

/2r
I'm trying to become President of the state I'm in...