Results 1 to 6 of 6
hello users
I use this syntax in a bash-script on kubuntu:
ls -lah --sort=size `cat $LOGFILE.tmp` | awk '{print $5 " " $8}' > $LOGFILE
now, the problem is, if ...
- 09-25-2008 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 28
awk capture column 2 to the end
hello users
I use this syntax in a bash-script on kubuntu:
ls -lah --sort=size `cat $LOGFILE.tmp` | awk '{print $5 " " $8}' > $LOGFILE
now, the problem is, if a filename (usualy in $
has a space inside, then the rest of the name is in $9 etc...
how can I say, and now from $8 to the Lineend?
thank you.
raphael
- 09-26-2008 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Use $NF to refer to the last column,
ls -lah --sort=size `cat $LOGFILE.tmp` | awk '{print $5 " " $NF}' > $LOGFILE
- 09-26-2008 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 28
hmm, not exactly, what I mean.
if I have this situation:
logfile:
75k /home/user/Text-File1.txt
72k /home/user/Text-File2.txt
78k /home/user/Text File3.txt
notice the "space" in the third line!
then process through:
cat logfile | awk '{print $2}'
then the third line is only: "/home/user/Text"
and not the exact Filename...
how can I change that?
- 09-26-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you have Python
Code:#!/usr/bin/env python for lines in open("logfile"): lines = lines.strip().split(" ",1) filename = lines[1] size = lines[0] print filename,size
- 09-27-2008 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Use cut (and not cat!)
Code:cut -d" " -f2- logfile
- 09-30-2008 #6Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
If all filenames starts with "/", you can use awk like this:
awk 'BEGIN{FS=" /"} {print "/"$2}' logfile


Reply With Quote