1833210 Members
2840 Online
110051 Solutions
New Discussion

Re: shell string parsing

 
SOLVED
Go to solution
andi_1
Frequent Advisor

shell string parsing

Hi guys,

I have the following entry:
0x016000

What is easiest way to retrieve, for example, 3rd, 4th and 5th component?

Thank you!
3 REPLIES 3
Rodney Hills
Honored Contributor
Solution

Re: shell string parsing

chr4=`echo "0x016000" | cut -c 4`

Will put the 4th character into env variable chr4.

-- Rod Hills
There be dragons...
S.K. Chan
Honored Contributor

Re: shell string parsing

..easiest way .. probably use cut ..

# echo 0x016000 | cut -c 3,4,5



SHABU KHAN
Trusted Contributor

Re: shell string parsing

Hi Leon,

As mentioned by others cut works well for your need:

HOSTA:/tmp:> cat test
0x016000

HOSTA:/tmp:> cut -c3-5 test
016

-Shabu