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!

Need help on how to cut string on a log file 2

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
US
I have a log file that contain a line below from sftp log
sftp> ls -lrt
drwxr-xr-x 1 22802 118581 96 Sep 12 12:24 sshkeys
-rw-r--r-- 1 0 0 2 Sep 28 17:48 epsout.Hi there you.txt
sftp> exit



Because there is a space in filename, my command below failed
Code:
cat sftp.log|grep epsout|awk '{print $9}'
failed to give me whole file name as "epsout.Hi there you.txt"

I've been searching but could not find a good solution for it.


Can some one help me
 
A starting point:
awk '/epsout/{for(i=1;i<9;++i)$i="";print}' sftp.log

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Yeah it work great. Thank you very much. Can you kindly explain the for portion of the command?
 
The same code with some comments:

Code:
awk '
        [green]/epsout/[/green] {
                [gray]# for each value of i from 1 to 8[/gray]
                [olive]for[/olive](i=1;i<9;++i) {
                        [gray]# set that field number to the empty string[/gray]
                        [blue]$i[/blue]=[red]"[/red][purple][/purple][red]"[/red]
                }
                [gray]# print remaining data (fields 9 onwards)[/gray]
                [b]print[/b]
        }
' sftp.[b]log[/b]



Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
A [tt]sed[/tt] solution...
Code:
cat sftp.log | sed -n 's/^.* epsout/epsout/g;/^epsout/p'
Not as nice as Annihilannic's solution, but it seems no thread is complete without both [tt]awk[/tt] and [tt]sed[/tt] solutions.

[bigsmile]

 
Actually... credit where it's due, the solution was PHVs. I just annotated it. :)

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top