Sed scripting issue

Hi all!

I was wondering if anyone could help suggest some solutions to an issue i'm having using the Sed command. I'm still a relative novice at this, but slowly learning and enjoying the power of batch processing.

I am using Sed to extract values from a .txt file containing hundreds of lines of data and input it into another file for processing. In shell script I set the following as my variable, which in this case is basically a certain number 664 lines down and 7-10 characters across. The position of this number will change by +1 line each time but i know how to sort that.

set day_txt = sed -n '664p' <KAN_runoff\(mm_water\)_VLF.txt | cut -c 7-10

this prints the number to the terminal so I know it works.

I then use another sed command to add this variable to an xml file to replace 'day' with the number.

sed -e 's/day/'$day_txt'/' <elevation.xml >elevation1.xml

The problem I have is during the second sed command 'day' isnt replaced by the value of '$day_txt' instead 'day' is just removed or by adding more inverted commas 'day' is replaced by '$day_txt' rather than the actual number.

I have tried the following to combine the commands but this doesn't work either.

sed -e 's/day/'sed -n '664p' <KAN_runoff\(mm_water\)_VLF.txt | cut -c 7-10'/' <elevation.xml >elevation1.xml

I hope this makes sense. In reality there are multiples of these commands feeding the xml files but just thought Id use this as an example as once one works the rest will too!
Ive spent a long time going over this and cant seem to find a solution so any suggestions will be much appreciated.

Many Thanks

Andrew

try using "

sed "s/day/$day_txt/" <elevation.xml >elevation1.xml
1 Like

Many Thanks Zorro, problem sorted!

Also, I realised that I didn't need the 'set' in

set day_txt = sed -n '664p' <KAN_runoff\(mm_water\)_VLF.txt | cut -c 7-10

thanks again!

Andrew