1752612 Members
4171 Online
108788 Solutions
New Discussion юеВ

Re: edit string with sed

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

edit string with sed

Hi all,

I'm trying to work out how to use sed to keep the 5th and 6th Characters from the below string - can someone explain how I can do this?

inndot1

I want to keep "ot"

Thanks

Chris
hello
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: edit string with sed

Hi Chris:

# X="inndot1"
# echo ${X}|sed -e 's/....\(..\).*/\1/'
ot

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: edit string with sed

I am not sure why you are hung on using sed for this job. sed is used more for editing, replacing large files or doing more complex tasks.

If your heart is not set on using sed, why not use cut as in

echo mystring | cut -c 5-6

________________________________
UNIX because I majored in cryptology...
Dennis Handly
Acclaimed Contributor

Re: edit string with sed

You could also use expr(1):
expr substr "$X" 5 2
lawrenzo_1
Super Advisor

Re: edit string with sed

all options are good for me - thanks all.
hello