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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed: -e expression #1, char 16: unterminated address regex
# 1  
Old 09-29-2016
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.

Few details of variables passed as a parameter:
Code:
server_id= hostname
first_line_log_file=sample.gz
first_line_date_time=2016-09-14 01:09:56,796
last_log_first_line=2016-09-15 04:10:29,719
do_action_on_cell_2=Do action on cell BL330
 
ssh -q -o "StrictHostKeyChecking no" $server_id "cd /intucell/data/logs/app; zcat $first_line_log_file | sed -rne '/$first_line_date_time/,/$first_log_first_line/p'| zgrep -A10 -i '$do_action_on_cell_2';" >> ./output.log

However, on executing the above i get the below error

Code:
sed: -e expression #1, char 62: unterminated address regex

I think the problem is with sed expression, Please suggest a way forward.




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by rbadveti; 09-29-2016 at 01:27 PM.. Reason: Added CODE tags.
# 2  
Old 09-29-2016
There seem to be several problems with your above code:
- shell variable assignment doesn't allow for spaces, so remove those around the "=" sign, and use quoting or escaping for the contents.
- don't expand (using the $ sign) the variable to be assigned to.
- within single quotes, no variable expansion is performed, so edit your sed and zgrep parameters. you may need to escape the $ sign within the ssh command line.
- I'm not sure zgrep makes sense after zcat | sed ... | .
# 3  
Old 09-29-2016
Hi RudiC, Thanks for quick reply and correcting the code format.

- Space in assignment of variable was a typo error, I have corrected it now. The variables given are only for providing more information to my question on the parameters used.

- I did not understand the 2nd point mentioned.

- There is a double quote in the code pasted, which i believe is taking care of variable expansion. Also below is another example which works perfectly fine and fetches me desired output:

Code:
ssh -q -o "StrictHostKeyChecking no" $server_id "cd /intucell/data/logs/app; zcat $first_line_log_file | tail -1| cut -d' ' -f1-2;"

- I will make changes to see if [CODE] zcat | zgrep and then [CODE] sed works or not.

Last edited by RudiC; 09-29-2016 at 12:41 PM.. Reason: Added [/CODE] tag
# 4  
Old 09-29-2016
Hi RudiC, Thanks for quick reply and correcting the code format.

- Space in assignment of variable was a typo error, I have corrected it now. The variables given are only for providing more information to my question on the parameters used.

- I did not understand the 2nd point mentioned.

- There is a double quote in the code pasted, which i believe is taking care of variable expansion. Also below is another example which works perfectly fine and fetches me desired output:

Code:
ssh -q -o "StrictHostKeyChecking no" $server_id "cd /intucell/data/logs/app; zcat $first_line_log_file | tail -1| cut -d' ' -f1-2;"

- I will make changes to see if
Code:
 zcat | zgrep

and then
Code:
 sed

works or not.

---------- Post updated at 08:42 PM ---------- Previous update was at 08:18 PM ----------

Just a quick update:

I have tried the below two options on remote server (hostname) directly on the file and results as below

1. zcat | sed | zgrep -> This works fine.

Code:
zcat sample.gz | sed -rne '/2016-09-14 01:09:56,796/,/2016-09-14 01:46:56,438/p' | zgrep -A10 -i "Do action on cell BL330"

2. zcat | zgrep | sed -> This does not print any output

Code:
zcat sample.gz | zgrep -A10 -i "Do action on cell BL330" | sed -rne '/2016-09-14 01:09:56,796/,/2016-09-14  01:46:56,438/p'

I suspect that the problem is with sed expression and escaping the correct characters.
Please have a look and suggest.
# 5  
Old 09-29-2016
Hi,
1. Worked because sed prints range of lines and in those lines grep looks for " "Do action on cell BL330" and print 10 lines after matched pattern.
2. Grep first prints only 10 lines . Sed looks for range of lines from the output of grep , may be it is not present.
Check the output of grep.

Note : you can use
zgrep <string to look> sample.gz
Zcat is not required , IMHO.
# 6  
Old 09-29-2016
Hi greet_sed,

Thanks for the reply.

I have tried like you mentioned but does not print any output:
without zcat:
Code:
zgrep -A10 -i "Do action on cell BLA330" sample.gz | sed -rne '/2016-09-14 01:09:56,796/,/2016-09-14 01:46:56,438/p'

Code:
sed -rne '/2016-09-14 01:09:56,796/,/2016-09-14 01:46:56,438/p' sample.gz | zgrep -A10 -i "Do action on cell BLA330"

The above commands are directly executed on the remote machine and hence the characters to be escaped are not taken into consideration.

My original problem lies in the below piece of line:
Code:
 
ssh -q -o "StrictHostKeyChecking no" $server_id "cd /intucell/data/logs/app; zcat $first_line_log_file | sed -rne '/$first_line_date_time/,/$first_log_first_line/p'| zgrep -A10 -i '$do_action_on_cell_2';" >> ./output.log

# 7  
Old 09-29-2016
After
Quote:
zcat is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) zcat uncompresses either a list of files
on the command line or its standard input and writes the uncompressed data on standard output.
(c.f. man zcat) there's no compressed data any more, so using zgrep is overkill (although it may work as zgrep recognizes and works on uncompressed data).

2nd point: you have
$do_action_on_cell_2=.... The $-sign is incorrect.

For the unterminated address regex error, we need to see what's going on. Try to run the command with the -vx options set to enable xtracing.
For the address range matching, the string you give for the starting address NEEDS to be found dot for dot, comma for comma, char for char, in the target file. Are you sure that's the case?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

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. for i in `cat servername`; do ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
Discussion started by: yash_message
4 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