Error in sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in sed command
# 1  
Old 07-09-2013
Error in sed command

Hi,

I am trying to run below script where my input file contains

Code:
 
URL 1:Port1
URL 2:Port2
URL 3:Port3

Code:
 
IFS=" "
#Loop through the file
HSFILE=/home/Temp/Components.txt
for line in $HSFILE ;do
Url=$(awk -F":" '{print $1}' $HSFILE)
Port=$(awk -F":" '{print $2}' $HSFILE)
echo $Url
echo $Port
cat Monitor_Template.hrb | sed -e "s/URL/$Url/g" | sed -e "s/port/$Port/g">> NEWFile_$(date +%F-%T).hrb
sleep 5
done

for single line in the input file this code is working fine but for multiple line in the code it is not working giving me below error

Code:
sed: -e expression #1, char 18: unterminated `s' command
sed: -e expression #1, char 11: unterminated `s' command

# 2  
Old 07-09-2013
You want to run it on every line of $HSFILE, but your awk seems to be using the entire file. you may need something like this

Code:
for line in $(cat $HSFILE)
do
  Url=$(echo $line |  awk -F":" '{print $1}')
  Port=$(echo $line |  awk -F":" '{print $2}')
  cat Monitor_Template.hrb | sed -e "s/URL/$Url/g" -e "s/port/$Port/g" >> NEWFile_$(date +%F-%T).hrb

# 3  
Old 07-09-2013
u can simplify it as

Code:
 
while read line ; do
echo $line|awk -F":" '{print $1" "$2}'|read Url Port
sed -e "s/URL/$Url/g" -e "s/port/$Port/g" Monitor_Template.hrb  >> NEWFile_$(date +%F-%T).hrb
done < $HSFILE

# 4  
Old 07-09-2013
Thansk Raja and Vidyadhar,

I am getting the ambigous redirection of file error now for

Code:
 
NEWFile_$(date +%F-%T).hrb

I think it is not redirecting the changes in the new file

Code:
sed -e "s/URL/$Url/g" -e "s/port/$Port/g" Monitor_Template.hrb  >> NEWFile_$(date +%F-%T).hrb

and it is creating 0kb file in result.

For your below code Raja,

Code:
 
for line in $(cat $HSFILE)
do
  Url=$(echo $line |  awk -F":" '{print $1}')
  Port=$(echo $line |  awk -F":" '{print $2}')
  cat Monitor_Template.hrb | sed -e "s/URL/$Url/g" -e "s/port/$Port/g" >> NEWFile_$(date +%F-%T).hrb


I need each varaible from the input file like URL 1 to replace first and port 1 second.
So my loop should run for three time and create three files after replacing the mentioned values in the input file.

---------- Post updated at 07:04 AM ---------- Previous update was at 06:42 AM ----------

Hi rajamadhavan

I tried your snippet of code

Code:
echo $line|awk -F":" '{print $1" "$2}'|read Url Port

if I echo $Url and $Port, It is not showing anything on the console. Value in file is getting replaced by null.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while using sed command

I have a few csv files in a directory and i am using sed command for processing the results from the filename.Details are given below: Directory: /tmp/test/output Files: JAN_DAT_TES1_201807181400.csv JAN_DAT_TES2_201807181500.csv I want to get the output as ... (5 Replies)
Discussion started by: Jag02
5 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

sed command error

When i pass parameter to sed command its throwing error as “SED cannot be parsed”.sed command is working if I pass directly.please tell me how to handle sed command with parameter.Please check below. n=14 `sed 's/'OCCURS $n TIMES'//g' main.txt >sam1.txt`-Not working `sed 's/OCCURS 14 TIMES//g'... (2 Replies)
Discussion started by: srivalli
2 Replies

4. Shell Programming and Scripting

sed command error-URGENT

sort.sh ------ ls -lSr|cat -n/*gives the detailed description o files with a serial number concatenated*/ i=0 n=10 j=$n if then while do (sh -C sub.sh $i $j)& ((i++)) ((j--)) done fi if then while do (sh -C sub.sh $i $j)& (1 Reply)
Discussion started by: dishak
1 Replies

5. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

6. Shell Programming and Scripting

sed: command garbled error

Hi all, Suppose that I want to update the db.password entry in the below properties file, db.username=admin db.password=qhKkBno2U5GEq5k/dnmGPA== //I want this line to be replaced by: "db.password=abc/123/" db.host=server db.port=22 db.sid=database However when... (2 Replies)
Discussion started by: isaacniu
2 Replies

7. UNIX for Dummies Questions & Answers

sed error unterminated `s' command

I have list of data I have cut down to format: I am using sed command to remove the sed 's/ Returns error: sed: -e expression #1, char 5: unterminated `s' command Full code line is: cat textFile | cut -d ' ' -f 4 | cut ':' -f 1 | sed 's/ Thanks, Please use next time code tags... (2 Replies)
Discussion started by: maximus73
2 Replies

8. Shell Programming and Scripting

sed command garbled error

sed: command garbled: s/ri="*"/ri=" what i did is you can see below sed "s/ri=\"*\"/ri=\"$newri\"/" $2 > output how to solve this (2 Replies)
Discussion started by: pasricha.kunal
2 Replies

9. Shell Programming and Scripting

sed command error

Hi, Could some one help me please ? When I execute this command # paste -s -d"^m" swagent.log | sed '{s/\"\./\"\.\n/g}' > swagent.new I get this error. sed: Function {s/\"\./\"\.\n/g} cannot be parsed. Many Thanks in advance Regards, Nagu (1 Reply)
Discussion started by: srnagu
1 Replies

10. Shell Programming and Scripting

sed: command garbled error.....

Dear friends, please give me the solution to the following query. If a file contains multiple tags of same name, then how to get the required string between the tags, in which the string begins with "W/X" i.e., file1.txt contains following text(please note that all the following tags are in... (1 Reply)
Discussion started by: swamymns
1 Replies
Login or Register to Ask a Question