![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to sort paragraphs by date within a file | nabmufti | Shell Programming and Scripting | 1 | 02-13-2008 05:33 PM |
| how to extract paragraphs from file in BASH script followed by prefix ! , !! and !!! | nabmufti | Shell Programming and Scripting | 6 | 02-09-2008 08:32 PM |
| filter the string from a file ?? | varungupta | Shell Programming and Scripting | 11 | 09-17-2007 11:11 PM |
| File filter | Dastard | Shell Programming and Scripting | 3 | 09-06-2007 02:50 PM |
| filter out certain column from a file | CamTu | Shell Programming and Scripting | 4 | 04-04-2005 07:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
I am trying to filter out those paragraphs that contains 'CONNECT', 'alter system switch logfile'. That means say the input file is : ------------------------------------------------------- Wed Jun 7 00:32:31 2006 ACTION : 'CONNECT' CLIENT USER: prdadm CLIENT TERMINAL: Wed Jun 7 00:32:31 2006 ACTION : 'alter system switch logfile' CLIENT USER: prdadm CLIENT TERMINAL: Wed Jun 7 00:32:31 2006 ACTION : 'CONNECT' CLIENT USER: prdadm CLIENT TERMINAL: Wed Jun 7 00:32:42 2006 ACTION : 'ALTER DATABASE CLOSE NORMAL' CLIENT USER: prdadm CLIENT TERMINAL: ---------------------------------------------------------------- I would like the output file to be : ---------------------------------------------------------------- Wed Jun 7 00:32:42 2006 ACTION : 'ALTER DATABASE CLOSE NORMAL' CLIENT USER: prdadm CLIENT TERMINAL: ---------------------------------------------------------------- Do you have any script to perform this, thank you very much . |
|
||||
|
I'm assuming the horizontal lines aren't actually in the file, and are just used instead of
Code:
code tags Here's a script: Code:
#!/bin/sh
SHOULDPRINT=1
function do_flush
{
if [[ ${SHOULDPRINT} -eq 1 && ! -z ${OUT} ]]
then
echo "${OUT}"
fi
}
while read LINE
do
if [[ -z ${LINE} ]]
then
do_flush
OUT=""
SHOULDPRINT=1
elif echo "${LINE}" | egrep -q "CONNECT|alter system switch logfile"
then
SHOULDPRINT=0
else
if [[ -z ${OUT} ]]
then
OUT="
${LINE}"
else
OUT="${OUT}
${LINE}"
fi
fi
done
do_flush
|
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|