sed remove statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed remove statement
# 1  
Old 09-24-2008
sed remove statement

I am having some problems with sed, that I am hoping that I can get some assistance with. I am trying to remove two subsets of a string, and cannot figure out how to have it work.

Here is an example string:

[Wed Sep 24 08:47:46 2008] [warn] [client xxx.xxx.xxx.xxx] [28580] auth_ldap authenticate: user joe authentication failed; URI /svn/ [User not found][No such object]

I want to use sed to remove [Wed Sep 24 08:47:46 2008] [warn] including the [ and ]. I only want the first two of these removed.

Suggestions or pointers on doing something like this?

I cannot do this in the apache conf file, as this sed statement is actually so that I can send SNMP trap data, I do not want to change what is going into the log files.
# 2  
Old 09-24-2008
Question What is meant by?

including the [ and ]

I do not see this in your sample one line.
By the way, it would be easier to visualize, code and test if we could see a few more sample data lines.
# 3  
Old 09-24-2008
Quote:
Originally Posted by joeyg
including the [ and ]

I do not see this in your sample one line.
By the way, it would be easier to visualize, code and test if we could see a few more sample data lines.
Sorry, I meant the characters "[" "]".

A couple more line of the error log can easily be provided.. Here ya go..

[Wed Sep 24 08:32:58 2008] [warn] module authz_svn_module is already loaded, skipping [already loaded]
[Wed Sep 24 08:33:00 2008] [warn] module dav_svn_module is already loaded, skipping [already loaded]
[Wed Sep 24 08:33:00 2008] [warn] module authz_svn_module is already loaded, skipping [already loaded]

I just want the first two statements removed (date string, and error levels).
# 4  
Old 09-24-2008
With awk you can remove the two blocks within the square brackets as follow:

Code:
 awk 'BEGIN{FS=OFS="]"}{$1=$2="";sub(/^\]* /,"")}{print}' file > newfile

Regards
# 5  
Old 09-24-2008
Thanks!

I begged some of the other guys I know to assist me, and they gave me two other options as well.. Here they are for anyone else who needs something like this..

sed -e 's/^\[[^]]*\] \[[^]]*\] //'

perl -pe 's/^\[.*?\] \[.*?\] //'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed within awk statement

input | Jan 8 2018 11:28PM| 24 | 75 | 51 | 1 | 1.600| | Jan 8 2018 12:01PM| 52 | 823 | 21 | 6 | 2.675| desired output Jan-8-2018-11:28PM 24 75 51 1 1.600 Jan-8-2018-12:01PM 52 823 21 6 2.675 Dear friends, I have input file , as shown above and... (10 Replies)
Discussion started by: sagar_1986
10 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

If else statement in sed

Hello Guys, I am new here and this is my first post, hope someone can help me I am writing a script that is supposed to go in 9 different directories and edit a given file in each of the directories. I am using sed to edit the file as sed -i 'line# s/#to be changed/#to be replaced with/... (5 Replies)
Discussion started by: Madiouma Ndiaye
5 Replies

4. Shell Programming and Scripting

sed if statement to see if file exists

Is there an easy way of checking for the existence of a file that ends with the extension .order and if it exists do something? if not do nothing (7 Replies)
Discussion started by: firefox2k2
7 Replies

5. Shell Programming and Scripting

If condition and for loop within sed statement

Hi, I tried to go through a lot of online material but could not find concrete solution. My issues is like this : I've got a input file like this : <a> <startDate>19700101000000</startDate> <endDate>20300101000000</endDate> </a> ... (12 Replies)
Discussion started by: Shaishav Shah
12 Replies

6. Shell Programming and Scripting

A complex sed statement

I have following requirement. Say, my text file contains following patterns {2010501005|XXGpvertex|9|0|17|0|{|{30100001|XXparameter_set|@@@@{{30001002|XXparameter|!prototype_path|$AB_COMPONENTS/Sort/Sort.mpc|3|2|Pf$|@{0|}} }}@0|@315000|78500|335000|99000|114000|87000|17|And the Sort|Ab... (8 Replies)
Discussion started by: Shell_Learner
8 Replies

7. Shell Programming and Scripting

How to remove a defined character on an array variable in a do while statement in ksh

I have a korn shell code here on a while do statement which replace the string stored on an array removing double quotes characters on it but it doesn't work. example record: appointmentDate = "tree" which value should result to tree #!/bin/ksh # Remove " on string records let recordCount=3... (5 Replies)
Discussion started by: ryukishin_17
5 Replies

8. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

9. Shell Programming and Scripting

Variables within a sed statement

I am just wondering if it's possible to refer to variables within a sed statement as follows:- cat $file | sed -e 1's/$oldtext/$newtext/' > $file as when I run the script, the variables are not recognised and nothing happens..?? Thanks (5 Replies)
Discussion started by: sirtrancealot
5 Replies

10. Shell Programming and Scripting

if and sed statement

this is my output for my crawler. /about.html /ads/ /advanced_search?hl=en froogle.google.com/frghp?hl=en&tab=wf&ie=UTF-8 groups.google.com/grphp?hl=en&tab=wg&ie=UTF-8 /imghp?hl=en&tab=wi&ie=UTF-8 /intl/en/options/ /language_tools?hl=en /maphp?hl=en&tab=wl&ie=UTF-8... (3 Replies)
Discussion started by: chris1234
3 Replies
Login or Register to Ask a Question