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:
However, on executing the above i get the below error
I think the problem is with sed expression, Please suggest a way forward.
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by rbadveti; 09-29-2016 at 01:27 PM..
Reason: Added CODE tags.
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 ... | .
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:
- 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
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:
- I will make changes to see if
and then
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.
2. zcat | zgrep | sed -> This does not print any output
I suspect that the problem is with sed expression and escaping the correct characters.
Please have a look and suggest.
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.
I have tried like you mentioned but does not print any output:
without zcat:
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:
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?
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)