1827295 Members
2543 Online
109717 Solutions
New Discussion

Re: Scripting Question

 
SOLVED
Go to solution
Craig Rants
Honored Contributor

Scripting Question

I have to breakdown the contents of a field in the same manner each time I come upon this field. The format of the field is 123456789XX0000. I want to remove the first 9 numbers from the field so the result would be XX0000. I know how I would approach this for command line arguments with shift. And I know how I could do this by processing each field through a while or for statment. But this is quite a big file and I don't want this to run all weekend. So basically my question is, is there a way to format the field in a similar manner to the shift command.

All responses are appreciated.

Craig
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripting Question

Hi Craig:

Try this:

# echo "123456789xxxx1234"|awk '{print substr($0,10,8)}'

Regards!

...JRF...
Craig Rants
Honored Contributor

Re: Scripting Question

Bingo!
Good to see the master at work.

Craig
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Deshpande Prashant
Honored Contributor

Re: Scripting Question

HI
One more choise if you need fields from 10th position through last.

echo "1234567890xabcdef" |cut -c 10-

Thanks.
Prashant.
Take it as it comes.
Darrell Allen
Honored Contributor

Re: Scripting Question

Hi Craig,

Here's another way:

echo "123456789xxxx1234"|cut -c10-

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Craig Rants
Honored Contributor

Re: Scripting Question

I had tried cut and I must have missed something in my syntax.

Now I know.

Craig
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
harry d brown jr
Honored Contributor

Re: Scripting Question

echo "123456789XX0000"|sed "s/^\([0-9]\{9\}\)\(.*\)/\2/"

for xx0000

or echo "123456789XX0000"|sed "s/^\([0-9]\{9\}\)\(..\)\(.*\)/\3/"

for 0000

live free or die
harry
Live Free or Die