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
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.
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
Below command deletes the line with the pattern,along with the next line.
sed '/%CLI-/{N;d;}' input.txt
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.
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......