Home » Infrastructure » Unix » Urgent Help
Urgent Help [message #98320] Wed, 21 July 2004 02:01 Go to next message
pulkit
Messages: 18
Registered: April 2004
Junior Member
HI,

I have a log file and i want to select all lines from this log file that contain word "Total" in it as a first word of line and then put all the selected lines into a saperate file.

How can i do it?

Please suggest ASAP.

Regards

Pulkit

 

 

 
Re: Urgent Help [message #98321 is a reply to message #98320] Wed, 21 July 2004 03:57 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
#
# samplefile is our sample file
#
# only lines 1 and 4 have the first word as "total"

bash-2.03$ cat samplefile
total something else
something else total
totalsomethingelse
total and this is new
newtotal and is this
nonew all something
#
# NOw using awk go through file samplefile
# only if the first word is exactly "total" print the whole line
# redirect the output to another file (here...anothersamplefile)
#
bash-2.03$ awk {'if ($1=="total") print $_}' samplefile > anothersamplefile
#
#
bash-2.03$ cat anothersamplefile
total something else
total and this is new

Re: Urgent Help [message #98322 is a reply to message #98320] Wed, 21 July 2004 05:24 Go to previous message
Jai Vrat Singh
Messages: 205
Registered: September 2002
Location: Singapore
Senior Member
-

This will select all line staring with word total (case insensitive) into a new file called selected.txt. In case you want it to be case sensitive then please remove -i


grep -i "^Total" yourfile.log > selected.txt



-
Previous Topic: ORA-12545 error on startup nomount
Next Topic: A shell script that login to sqlplus
Goto Forum:
  


Current Time: Fri Mar 29 04:45:40 CDT 2024