Sed: -e expression #1, char 20: unterminated address regex


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Sed: -e expression #1, char 20: unterminated address regex
# 1  
Old 05-17-2019
Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line.
the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex"

Please help.

Code:
for i in `cat servername`;
do
ssh -q -t root@$i  sed -i '/simple_allow_groups =/s/$/, group-name1/' /etc/sssd/sssd.conf
done

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 05-17-2019 at 02:16 PM..
# 2  
Old 05-17-2019
Just a shot in the dark: try enclosing the entire sed command in double quotes.
# 3  
Old 05-17-2019
I'm with Rudi. When I have problems trying something like a complex sed command over ssh because of quoting
Steps
1. make a note of my current shell - let's say it is bash
2. play with my command on one "home" box.
3. once I got it working at "home":
paste the command into a simple two line shell script, let's call it t.sh
Code:
#!/bin/bash    
[paste required external env variables here if needed]
[paste command here]

4. automate it:
Code:
for i in `cat servername`
do
   scp myusername@$i t.sh /tmp/t.sh
   ssh myusername@$i 'chmod +x /tmp/t.sh && /tmp/t.sh'
done

This looks like a lot of work. It is not. But when you execute a complex remote one-liner command it can mess up by being garbled by ssh and your command line or wrong environment variable settings. Explaining to management why your script trashed 10 servers is a whole lot more work and time consuming.
# 4  
Old 05-17-2019
Why scp? The script can be passed via stdin to the remote shell.
Code:
for i in `cat servername`
do
   ssh "myusername@$i" /bin/bash <t.sh
done

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 05-18-2019
Thanks Rudic.
Its working now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed: -e expression #1, char 16: unterminated address regex

I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine. ... (23 Replies)
Discussion started by: rbadveti
23 Replies

2. Shell Programming and Scripting

Unterminated Regular Expression

It is ok when I send send one arguement to $TILL in the awk expression. first(){ TILL=$1 echo $TILL awk '/:\\/ {P=0} P {print $0 "<br>"} FNR==1{printf("File %s:<br>", FILENAME)} /'$TILL'\/ {P=1} ' ${dirlist } } echo "<table border = '1'>" echo '<tr><td> </td><td>' ;... (3 Replies)
Discussion started by: alvinoo
3 Replies

3. Shell Programming and Scripting

Sed: -e expression #1, char 2: extra characters after command

Greetings.. getting the error while execution of the script, correct where i am missing #!/bin/bash DATE=`date +%Y-%m-%d:::%H:%M` HOSTNAME=`hostname` TXT="/log/temp.txt" LOGPATH="/log1/commanlogs/" IP=`/sbin/ifconfig | grep -i inet| head -n1| awk '{print $2}'| awk -F : '{print $2}'`... (7 Replies)
Discussion started by: manju98458
7 Replies

4. 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

5. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

6. Shell Programming and Scripting

SED With Regex to extract Email Address

Hi Folks, In my program, I have a variable which consists of multiple lines. i need to use each line as an input. My intention is to extract the email address of the user in each line and use it to process further. The email address could be anywhere in the whole line. But there will be only... (5 Replies)
Discussion started by: ragz_82
5 Replies

7. Shell Programming and Scripting

sed: -e expression #1, char 21: unterminated `s' command

I have read many threads, but I still didn't find the right answer. May be i didn't find the right thread, though are so many threads for the same question. Basically the situation is - find date in a file and replace it with another date. (its not homework, its part of lot of a big processing,... (10 Replies)
Discussion started by: avinthm
10 Replies

8. Shell Programming and Scripting

sed unterminated `s' command?

Hi there, I'm pretty new to this whole scripting thing. I've written myself something which takes my txt file of SMSes (the backup from the phone), and puts them into an email format, saving them as .eml files. I've tested and uploaded a batch to gmail, but because of threading issues, I've... (1 Reply)
Discussion started by: donnacha
1 Replies

9. Shell Programming and Scripting

Using SED command in a shell script: Unterminated address regex

Hi All, I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message. I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working. sed: -e expression #1,... (7 Replies)
Discussion started by: Alpha3363
7 Replies

10. Shell Programming and Scripting

Regex/sed - matching any char,space,underscore between : and /

trying to remove the portion in red: Data: mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql output to be: mds_ar/bin/uedw92wp.ksh: wkly.sql mds_ar/bin/uedw92wp.ksh: wkly.sql SED i'm trying to use: sed 's/:+\//: /g' input_file.dat >... (11 Replies)
Discussion started by: danmauer
11 Replies
Login or Register to Ask a Question