sed help needed badly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed help needed badly
# 1  
Old 06-26-2008
sed help needed badly

how can I delete one line above and below the matching pattern ?
e.g I want to delete the line above and below the line with %CLI- in example below :

$CHECKSUM $1$DGA1043:[ORACLE.PATRON]TSTST01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
-RMS-E-FLK, file currently locked by another user

thanks .
# 2  
Old 06-26-2008
This is example to remove 6 line before and after line $rmv_lbl

Code:
 # prepare file for testing:
n=0; fl=for_removing_lines.txt; rmv_lbl="point of removing"; rm $fl; 
while [ $n -le 20 ];do  
   (( n++ )); ec "line $n">>$fl; 
   if [ $n -eq 10 ]; then 
      ec $rmv_lbl>>$fl; 
   fi; 
done;

 # geting line numbers to statr and END remuving 
pnt_ln=`nawk -v srch="$rmv_lbl" '{if($0~srch) print NR; }' $fl`; 
((rmv_st=pnt_ln-6)); 
((rmv_end=pnt_ln+6));     ec $pnt_ln, $rmv_st, $rmv_end

 # printing file without 6 lines before and after label line
nawk -v st=$rmv_st -v end=$rmv_end '{if( (NR <= st)||(NR >= end) ) print $0; }' $fl

# 3  
Old 06-26-2008
Im not sure whether its gonna help you or not,
but what popped to my mind:

in case you know which line is :
you can use sed in deleting line

in case you are looking inside a file and you dont know which line its:
you might have to use regular expression like
[^%cli]---> look for everything except %cli

or you can use % as a delimiter in some commands % and make it as a field.

Im not sure wich one might help you,

i hope to be usefull
# 4  
Old 06-27-2008
I only want solution with sed first ..second what I want is follows :

I want these the following three lines


$CHECKSUM $1$DGA1043:[ORACLE.PATRON]TSTST01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
-RMS-E-FLK, file currently locked by another user


reduced to

%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF

using sed ..so how can I do it? I know its possible just dont know the syntax.
# 5  
Old 06-27-2008
forgot to add : yes I know which line Iam looking for .. it is the line starting with %CLI-E
and yes all these lines are in a file.
# 6  
Old 06-27-2008
Hi,

Below command deletes the line with the pattern,along with the next line.

Code:
sed '/%CLI-/{N;d;}' input.txt



Code:
I want these the following three lines


$CHECKSUM $1$DGA1043:[ORACLE.PATRON]TSTST01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
-RMS-E-FLK, file currently locked by another user

reduced to 

%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF

If my understanding is right,

For the above one, you can use sed or grep to find the line matching the pattern '%CLI-' and redirect it to a temp file.

Regards,
Chella
# 7  
Old 06-27-2008
can u try like this:

sed -n '/^%CLI-E/p' file_name

i got output only the lines starting with %CLI-E :

$ cat del_file
HECKSUM $1$DGA1043:[ORACLE.PATRON]TSTST01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
-RMS-E-FLK, file currently locked by another user
$ sed -n '/^%CLI-E/p' del_file
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF

let me know whether its working or not bcoz am also in learning stage......

Last edited by sujana; 06-27-2008 at 06:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Badly placed ()'s

Edit - I don't know how to delete posts. The question I asked here ended up not being the question I should have asked as I didn't realise I needed to edit my script to comply with SGE. Hi, My script is: #!/bin/bash # Perform fastqc on files in a specified directory. for ((j=1;... (8 Replies)
Discussion started by: una1992
8 Replies

2. Shell Programming and Scripting

sed Help Needed

I want to search texts between first occurence of the matching pattern and replace it with some other text.pls advice what can be done. I searched alot, i could not find anything relevant. Ex my input is as follows: red yellow grey white blue red pink violet white I want to search... (9 Replies)
Discussion started by: sangitajc
9 Replies

3. Shell Programming and Scripting

some sed help needed

I have file with following contents; 127.0.0.1 www.google.com 127.3.3.1 www.cisco.com 127.3.5.1 www.msnbc.com I want output as 127.0.0.1 www.google.com google.com 127.3.3.1 www.cisco.com cisco.com 127.3.5.1 www.msnbc.com msnbc.com I tried sed 's/www.//g'... (5 Replies)
Discussion started by: sangfroid
5 Replies

4. Shell Programming and Scripting

badly placed ()'s

i'm trying to run the following program but i keep getting the message "badly placed ()'s" can u help? #include "modularity_mat.h" #include "../sparse_mlpl/sparse_matrix.h" adj_matrix_arr* allocate_mem_for_matrix_arr (int y) { /* Create the adj matrix and allocate memory */ ... (2 Replies)
Discussion started by: ronirosner
2 Replies

5. UNIX for Dummies Questions & Answers

SED Help Needed

I am trying to retrieve part of a line from /boot/grub/menu.lst The line is : gfxmenu (hd0,0)/usr/share/gfxboot/themes/pclinuxblue/boot/message I have figured out how to get this line into a file by itself. sed '/gfxmenu/ !d' /boot/grub/menu.lst > /tmp/menu.lst.pcl_tc What I need to... (2 Replies)
Discussion started by: Tide
2 Replies

6. Shell Programming and Scripting

Sed help needed

Hi, I have the following texts : #1#http://www.google.com#2#Google#3# #1#http://www.aol.com#2#AOL#3# I need a bash script which extracts the text between the markers (marks are #1#,#2#,#3#). I also need that text in variables ($URL and $DESCRIPT will be fine) so I can later use it to... (3 Replies)
Discussion started by: tcp27br
3 Replies

7. Shell Programming and Scripting

help with sed needed

Hi, I have a file in a form of jkkhjjk1:!:jkhdjkhjkh2:!:kljkljkljklj3:!:kljsdj4 kljlkfljf5:!:kjljljlj6:!:jhjkhjkh7 I am trying to use sed command such that everytime it find ":!:" it will removes it and print remaining of the line on the new line Output that I need will look like following... (8 Replies)
Discussion started by: arushunter
8 Replies

8. Shell Programming and Scripting

Help Needed -sed

Hi All, i have one file and in that i have to read each line and do some replacement. its is not fixed the number or column always be same it can be less also exm a;b;c;d;e;f (line) i have to do something like In the line If c is present then go to end of line and append ';date' else... (9 Replies)
Discussion started by: ravi.sadani19
9 Replies

9. Shell Programming and Scripting

Sed help needed

Could someone tell me how to replace varibles using SED inside Korn Shell? e.g. I have a ksh file program.ksh below: ------------------------------------ #!/bin/ksh sed -n '/ABC/p' $1 > output.txt if ] then status=new elif ] then status=old fi sed -n '/$status/p' $1... (5 Replies)
Discussion started by: stevefox
5 Replies

10. UNIX for Dummies Questions & Answers

Help needed with sed

Hi, I need to insert a line into a file underneath an existing line in the file, but am unsure as to the syntax. I'm pretty sure sed can be used though, although any ideas are more than welcome. For example: File ---- Line 1 Line 2 Line 3 Line 4 Line 6 I need to say: Insert "Line 5"... (1 Reply)
Discussion started by: danhodges99
1 Replies
Login or Register to Ask a Question