Operating System - HP-UX
1834142 Members
2167 Online
110064 Solutions
New Discussion

grep/sed records with positional param

 
Dai_3
New Member

grep/sed records with positional param

Hi,
I'm little new in UNIX, how I can select some recs from file, based on the value of string in certain position, let say I need all rec with '-mm-' in pos.136.

Thanks to all
+ nice weekend

Dai
4 REPLIES 4
Sandman!
Honored Contributor

Re: grep/sed records with positional param

To print all lines that have "-mm-" (a dash in position 136 followed by two m's and then a dash) use the awk contruct below:

# awk 'match(substr($0,136,4),/-mm-/)' infile

~cheers
Sandman!
Honored Contributor

Re: grep/sed records with positional param

Minor correction to my last post...change the awk command as follows:

# awk 'match(substr($0,136,4),"-mm-")==1' infile

~cheers
James R. Ferguson
Acclaimed Contributor

Re: grep/sed records with positional param

Hi Dai:

Similarly, in Perl:

# perl -ne 'print if substr($_,136,4)=~/-mm-/' file

Regards!

...JRF...
Sandman!
Honored Contributor

Re: grep/sed records with positional param

and here's how to do the same thing with grep/sed

# grep '^.\{135\}-mm-' file

# sed -n '/^.\{135\}-mm-/ p' file