Sed scripting issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed scripting issue
# 1  
Old 08-02-2011
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.

Code:
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.

Code:
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.

Code:
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

Last edited by radoulov; 08-02-2011 at 09:17 AM.. Reason: Code tags.
# 2  
Old 08-02-2011
try using "
Code:
sed "s/day/$day_txt/" <elevation.xml >elevation1.xml

This User Gave Thanks to maskofzorro For This Post:
# 3  
Old 08-02-2011
Many Thanks Zorro, problem sorted!

Also, I realised that I didn't need the 'set' in
Code:
set day_txt = sed -n '664p' <KAN_runoff\(mm_water\)_VLF.txt | cut -c 7-10

thanks again!

Andrew

Last edited by Franklin52; 08-02-2011 at 03:37 PM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting issue

Hi Experts, I'm stuck with a single liner bash script. Need your help to fix it. Let me brief you that what is my expectations from this script. I need the interfaces configured for a list of servers, their respective IP address and FQDN in a output file. The output should be in the same... (3 Replies)
Discussion started by: arun_adm
3 Replies

2. Shell Programming and Scripting

Scripting issue

I am having a problem. which I have described below>> I have to run a script with the format : <File_name><Start_date><End_date> abcd.sh 19-JAN-2015 01-May-2014 problem is I need to compare these two dates and throw an error as start date must be less than or equal to end date. But... (13 Replies)
Discussion started by: Chandan_Bose
13 Replies

3. UNIX for Dummies Questions & Answers

Scripting issue

Hi experts... I am really new to this scripting, i really need your help. I have this script to read and print the report, however the script does not pickup the correct hostname (eg. Svtns11d).. The script will start reading/pick up on the second line instead of reading the first line.... (1 Reply)
Discussion started by: talkhard154
1 Replies

4. Shell Programming and Scripting

Scripting Issue

needing this script to shut down 1 IceS and start up another, close the 2nd one after 12 seconds and then reboot. here is what i have so far #!/bin/bash ShutDown() { echo "Shutdown in progress." wall <<ENDOFWALL CI Shutdown has been intiated!!!! Shutdown will occur in 30 seconds...... (1 Reply)
Discussion started by: Zaine
1 Replies

5. Shell Programming and Scripting

Scripting issue

Hello, I have an ASCII file (many files of the same format, but different dates and numbers) in the format like below: 2008.01.02,08:00,1.46520,1.46520,1.46410,1.46440,70 2008.01.02,08:05,1.46450,1.46560,1.46440,1.46540,79 2008.01.02,08:10,1.46530,1.46540,1.46490,1.46500,46... (8 Replies)
Discussion started by: chief2000
8 Replies

6. Shell Programming and Scripting

IP-Scripting Issue

Hi Guys, I am quite new to Shell Scripting... I need ur help.. This is very urgent. The thing is like, I need to match a IP address (ex 192.168.200.56) i.e, xxx.xxx.xxx.xx inside a KSH script,but if we enter in different format other than the specified format (ex jjj.ksj., 1.0...), it should... (3 Replies)
Discussion started by: mraghunandanan
3 Replies

7. Shell Programming and Scripting

Scripting issue..

Hi guys... I am newbie to Shell Scripting... I am querying the Oracle database.I want a Shell script for fetching some data from datasets in Oracle database and displaying in an excel sheet.This is my requirement.. Can u plz help me guys.. Regards, Mahesh... (4 Replies)
Discussion started by: mraghunandanan
4 Replies

8. Shell Programming and Scripting

Scripting issue..

Hi guys... I am a newbie to scripting... I have a small requirement... I dont whether u r clear with my requirement... But plz try to help me... Like, tell me some kind of scripts that can help me in retreiving the data from the datasets. Regards, Mahesh... (1 Reply)
Discussion started by: mraghunandanan
1 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. Shell Programming and Scripting

scripting issue

folks; i'm trying to write a shell script to do the following: 1. i have a file with 39 fields, i'm trying to add 10 more fields with (!) as a field separator. with the following requirement: if field number 20 has a value, then field number 40 will show as (!M!), and if the field number 20 does... (2 Replies)
Discussion started by: moe2266
2 Replies
Login or Register to Ask a Question