Re: how to select lines from file? (297 Views)
Reply
Esteemed Contributor
Henk Geurts
Posts: 299
Registered: ‎08-18-2002
Message 1 of 9 (297 Views)
Accepted Solution

how to select lines from file?

Hi guys..
I have a file with lines like :

aabbddcc1234xxxx
aa1234cc2345yyyy
aa1234xx3456zzzz

How can i select the lines that have certain string in caracters 10-14 ?

Honored Contributor
Rita C Workman
Posts: 3,791
Registered: ‎08-03-2000
Message 2 of 9 (297 Views)

Re: how to select lines from file?

man grep

grep aa1234cc /path/filename

Just a quick thought,
Rita
Esteemed Contributor
Henk Geurts
Posts: 299
Registered: ‎08-18-2002
Message 3 of 9 (297 Views)

Re: how to select lines from file?

oke .. I have to make it more clear..

aabbddcc1234xxxx
aa1234cc2345yyyy
aa1234xx3456zzzz

when i to select the line with caracters 8-11 to be 1234 , grep will also show other lines.. as grep does not use the place of the caracters in the line..

Can awk do this ?
What will be the command.. ?
regards
Trusted Contributor
sreekanthtm
Posts: 298
Registered: ‎07-24-2006
Message 4 of 9 (297 Views)

Re: how to select lines from file?

Sorry qust: is not clear for me...
Honored Contributor
Rita C Workman
Posts: 3,791
Registered: ‎08-03-2000
Message 5 of 9 (297 Views)

Re: how to select lines from file?

How about:

grep '.......1234*' /path/filename

That's seven dots or periods then 1234 and anything else after that...

Rgrds,
Rita
Honored Contributor
john korterman
Posts: 1,117
Registered: ‎11-15-2000
Message 6 of 9 (297 Views)

Re: how to select lines from file?

Hi Henk,

another quick thought:

grep -E "........1234*" ./infile


regards,
John K.
it would be nice if you always got a second chance
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 7 of 9 (297 Views)

Re: how to select lines from file?

Hi Henk:

Using your data and using 'awk' [because that's one way] you could do:

# awk '{if (substr($0,9,4)==1234) {print}}' file
aabbddcc1234xxxx

Regards!

...JRF...
Esteemed Contributor
Henk Geurts
Posts: 299
Registered: ‎08-18-2002
Message 8 of 9 (297 Views)

Re: how to select lines from file?

Thanks James..
This was what I was looking for!!!

regards,
Henk
Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 9 of 9 (297 Views)

Re: how to select lines from file?

>when I select the line with characters 8-11 to be 1234

(Typically line positions start with 1, your example seems to be 0.)
An old thread about it:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=76665

Or for your case for columns 9-12.
grep '^.\{8\}1234' file
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.