Operating System - HP-UX
1748213 Members
3063 Online
108759 Solutions
New Discussion юеВ

Re: how to select lines from file?

 
SOLVED
Go to solution
Henk Geurts
Esteemed Contributor

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 ?

8 REPLIES 8
Rita C Workman
Honored Contributor

Re: how to select lines from file?

man grep

grep aa1234cc /path/filename

Just a quick thought,
Rita
Henk Geurts
Esteemed Contributor

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
sreekanthtm
Trusted Contributor

Re: how to select lines from file?

Sorry qust: is not clear for me...
Rita C Workman
Honored Contributor

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
john korterman
Honored Contributor

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
James R. Ferguson
Acclaimed Contributor
Solution

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...
Henk Geurts
Esteemed Contributor

Re: how to select lines from file?

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

regards,
Henk
Dennis Handly
Acclaimed Contributor

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