Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script question (Remove certain lines from a text file)

Status
Not open for further replies.

boym1

MIS
May 1, 2002
5
0
0
US
Hi,

Can anyone tell me how in a script to make the original input below look like the desired output also shown below. Want to get rid of the lines that only have one [number] and keep the lines that have two lines with the same [number]? Thanks.....

Original :
05:20:13 [1159] OracleH3
05:22:16 [1159] 178741 Kbytes at 1619.574 Kbytes/sec
14:49:35 [11630] 497376 Kbytes at 4048.645 Kbytes/sec
04:08:15 [11635] OracleH3
04:11:17 [11635] 468679 Kbytes at 2718.051 Kbytes/sec
05:20:13 [1160] SDP1_exp
05:22:16 [1160] 1782741 Kbytes at 1619.574 Kbytes/sec
14:49:35 [19830] 497376 Kbytes at 4048.645 Kbytes/sec
04:08:15 [11636] PRD3
04:11:17 [11636] 468679 Kbytes at 2718.051 Kbytes/sec


Desired Output: Lines with [11630] and [19830] removed - numbers will change.

05:20:13 [1159] OracleH3
05:22:16 [1159] 178741 Kbytes at 1619.574 Kbytes/sec
04:08:15 [11635] OracleH3
04:11:17 [11635] 468679 Kbytes at 2718.051 Kbytes/sec
05:20:13 [1160] SDP1_exp
05:22:16 [1160] 1782741 Kbytes at 1619.574 Kbytes/sec
04:08:15 [11636] PRD3
04:11:17 [11636] 468679 Kbytes at 2718.051 Kbytes/sec




 
egrep -v "\[11635\]|\[19830\]" some_file

OR

egrep -v "11635|19830" some_file

Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Ahh.. first i need to come up with something
to find out which lines have duplicate numbers... Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
#!/usr/bin/ksh

SOURCE_FILE=data1

cat $SOURCE_FILE|while read LINE
do
CODE=`echo $LINE|awk -F"[" '{print $2}'|awk -F"]" '{print $1}'`
LINE_COUNT=`grep $CODE $SOURCE_FILE|wc -l`
if [ $LINE_COUNT -gt 1 ]
then
echo $LINE
fi
done Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Maybe my description was not clear but for this one the forms of grep will not work as the numbers in the []'s change.

:)
 
Sorry sent that before your second posting arrived :) Thank You I'll give it a try :)
 
I don't think that should matter.
Here's an example of what the awk statements will do
even if there are more than one set of [] per line

LINE="05:22:16 [1159] 178741 [Kbytes] at 1619.574 Kbytes/sec"

echo $LINE|awk "]" '{print $2}'
will print to the right of the first [ bracket
giving the result: 1159] 178741 [Kbytes] at 1619.574

LINE="1159] 178741 [Kbytes] at 1619.574"

echo $LINE|awk -F"]" '{print $1}'
will print to the left of the first ] braket
giving the result: 1159

If you are talking about another scenario,
please give an example.







Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Robert,

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!! I am trying to learn awk and sed more but it is going slow.. Thanks so very much for your help.....

Netbackup bptm log.050102 for Log file log.050102
**********************************************************
09:34:01 [14692] vincetst
09:44:52 [14692] 1286683 Kbytes at 2603.615 Kbytes/sec
14:06:29 [19989] xerox
14:32:00 [19989] 810348 Kbytes at 598.643 Kbytes/sec
ush4:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top