sed remove expression from output I'm watching


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed remove expression from output I'm watching
# 1  
Old 04-18-2012
sed remove expression from output I'm watching

I'm watching a particular expression as it is appended in a line to a file:
Code:
tail -f LOG | sed -n /"$@"/p

So whatever value I pass into this script will tail -f the file, but only show me lines that contain the value:
Code:
lgwatch expression

However some of the output contains a #20 control character (or translation of a control character - whatever). I want it removed from the output. I tried a few variations with the scipt:
Code:
sed -n /"$@"/p;'s/\#20//g'
sed -n -e /"$@"/p;'s/\#20//g'
sed -n /"$@"/p;s/\#20//g
sed -e 's/\#20//g';/"$@"/p
sed 's/\#20//g' '/"$@"/p'

I can't seem to get these #20's removed. Can anyone suggest?
# 2  
Old 04-18-2012
Could you show your actual output please?
# 3  
Old 04-18-2012
Well there is no output when I add the additional sed statement - that's how I come to the conclusion that it's not working.
# 4  
Old 04-18-2012
Obviously. I mean the output you had before, still containing the bad characters you wanted removed.
# 5  
Old 04-18-2012
Here's an example substituting names to protect the innocent:
Code:
[user@hostname]lgwatch command
user MIKE entered command /usr/bin/tail#20-f#20/var/adm/log

# 6  
Old 04-20-2012
I just realized something. If $@ is ever more than one parameter, it will split into individual arguments in your sed statement, even inside double-quotes! That is $@'s function, to split on arguments and nowhere else... Try "$*" inside double quotes instead.
# 7  
Old 04-21-2012
Thanks for your continued support. I did try using an asterisk instead but I'm still not getting the desired result. I'm really confused on how to add the secondary sed statement without wrecking this whole thing. As you see before I've googled various ways to combine sed statements but it doesn't seem to be working as it should.

These attempts do not remove the #20's:
Code:
sed -n /"$*"/p | sed 's/#20//g'
sed -n /"$*"/p;'s/#20//g'
sed -n /"$*"/p | sed -e 's/#20//g'
sed -n /"$*"/p;"s/#20//g"
sed -n /"$*"/p | sed 's/\#20//g' (also with the above combinations)

I tried outputting results to a text file and then using the following sed and it worked:
Code:
sed 's/#20/ /g' txt

Granted instead I'm replacing the #20's with spaces but it still works. So I believe my sed statement is correct, but it seems I'm not appending it correctly. Can anyone advise how it should be added onto my tail command?

** Update **

I can search just for the expression I'm looking for - which gets passed into $@ or $* (tried both) so it appears that the issue is piping a sed statement for removing the #20's is the problem. Sed using -n '/$@/p' isn't a problem, but damnit if I put sed 's/#20/ /g' on the end that just kills any output. I've tried putting \#20 as well as including it in double quotes. What is the problem with my sed statement?

*** update ***

I moved the sed statement to the beginning of my tail statement and somehow this works. I guess it pulls all the #20's from everything before it does the tail...not really sure why I have to do this and piping the sed statement at the end kills it.

Last edited by MaindotC; 04-21-2012 at 10:52 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

2. Shell Programming and Scripting

How does this sed expression to remove non-alpha characters work?

Hello! I know that this expression gets rid of non-alphanumeric characters: sed 's///g' and I understand that it is replacing them with nothing - hence the '//'-, but I don't understand how it's doing it. It seems it's finding strings that begin with alphanumeric and replacing them with... (2 Replies)
Discussion started by: bgnersoon2be#1
2 Replies

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

4. Shell Programming and Scripting

sed & remove duplicates on output

sed -e '1d' -e 's/^\(]\{2\}\)-\(]\{3\}\)-\(]\{4\}\).*/"0000020\1\200\3"\,/g' abc.txt This script returns many duplicates due to the duplciates in the .txt file. i.e. ... "000002012149000060", "000002012149000064", "000002012149000064", "000002012149000064", "000002012149000064",... (9 Replies)
Discussion started by: Daniel Gate
9 Replies

5. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Augáá7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

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

7. Shell Programming and Scripting

Need perl regular expression to remove the comment

I need a perl substitution to remove only the comment in the line . That line may have '#' with in double quotes .I used the following , s/(^.*\".+?#.+?\".+?)(#.*)/$1/g It works for , print " not a comment # not a comment " . "not a comment # not a comment" ; # It is a comment ... (3 Replies)
Discussion started by: karthigayan
3 Replies

8. Shell Programming and Scripting

watching for a file

Hi dears, The script should watch for a file in particular directory. If the file not come into the directory even after 30 seconds from execution of the script, then script should exit saying “file not arrived” Any help ?? (4 Replies)
Discussion started by: Gopal_Engg
4 Replies

9. Shell Programming and Scripting

Need to remove improperly formatted fortran output line from files, tried sed

I have been trying to remove some improperly formatted lines of output from fortran code I have been using. The problem is that I have some singularities in the math for some points that causes an incorrectly large value to be reported that exceeds the normal formating set in the code resulting in... (2 Replies)
Discussion started by: gillesc_mac
2 Replies
Login or Register to Ask a Question