What's wrong with this cut utility command?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > What's wrong with this cut utility command?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    What's wrong with this cut utility command?  
KAKA


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:17 AM

I am trying read filelist.log and strip out all file attributes and
print only the full path filname to output.log.  The command (2 below)
I tried does not generate the appropriate output.  (NOTE: I even tried
to issue cut without the -d switch, since tab is the default delimiter
for cut, it still doesn't work) What am I doing wrong here?

Here is what I issued on the command line:

cut -f11 -d '  ' filelist.log > output.log

OR since some paths come with directory / file names with space.  I
would use this also:

cut -f 11-20 -d '  ' filelist.log > output.log


Here is my filelist.log:

23151931   43 -rwxrw-r--  1 www      www         43520 Oct  8  2004 /
export/home/qa/Utils/All 3rd Party Version/Docs/thirdparty.doc
33219855 3048 -rwxrw-r--  1 www      www       3109936 Jun 18  2004 /
export/home/qa/Utils/All 3rd Party Version/Popular Versions/VPN
_PPC/movianvpn-3.05-ppc2002.exe

Here is my output.log

23151931   43 -rwxrw-r--  1 www      www         43520 Oct  8  2004 /
export/home/qa/Utils/All 3rd Party Version/Docs/thirdparty.doc
33219855 3048 -rwxrw-r--  1 www      www       3109936 Jun 18  2004 /
export/home/qa/Utils/All 3rd Party Version/Popular Versions/VPN
_PPC/movianvpn-3.05-ppc2002.exe






[ Post a follow-up to this message ]



    Re: What's wrong with this cut utility command?  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 06:19 AM

In article <1173815791.063040.56750@s48g2000cws.googlegroups.com>,
"KAKA" <kaka.hui@gmail.com> wrote:

> I am trying read filelist.log and strip out all file attributes and
> print only the full path filname to output.log.  The command (2 below)
> I tried does not generate the appropriate output.  (NOTE: I even tried
> to issue cut without the -d switch, since tab is the default delimiter
> for cut, it still doesn't work) What am I doing wrong here?

Cut does not treat multiple delimiters in a row as a single delimiter.
So it's not useful for files where you can have varying amounts of
whitespace between the columns.

Use awk instead:

awk '{print $11}'

>
> Here is what I issued on the command line:
>
> cut -f11 -d '  ' filelist.log > output.log
>
> OR since some paths come with directory / file names with space.  I
> would use this also:
>
> cut -f 11-20 -d '  ' filelist.log > output.log
>
>
> Here is my filelist.log:
>
> 23151931   43 -rwxrw-r--  1 www      www         43520 Oct  8  2004 /
> export/home/qa/Utils/All 3rd Party Version/Docs/thirdparty.doc
> 33219855 3048 -rwxrw-r--  1 www      www       3109936 Jun 18  2004 /
> export/home/qa/Utils/All 3rd Party Version/Popular Versions/VPN
> _PPC/movianvpn-3.05-ppc2002.exe
>
> Here is my output.log
>
> 23151931   43 -rwxrw-r--  1 www      www         43520 Oct  8  2004 /
> export/home/qa/Utils/All 3rd Party Version/Docs/thirdparty.doc
> 33219855 3048 -rwxrw-r--  1 www      www       3109936 Jun 18  2004 /
> export/home/qa/Utils/All 3rd Party Version/Popular Versions/VPN
> _PPC/movianvpn-3.05-ppc2002.exe

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***





[ Post a follow-up to this message ]



    Re: What's wrong with this cut utility command?  
Michael Paoli


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-07 06:20 AM

Barry Margolin wrote:
> In article <1173815791.063040.56750@s48g2000cws.googlegroups.com>,
>  "KAKA" <kaka.hui@gmail.com> wrote: 
>
> Cut does not treat multiple delimiters in a row as a single delimiter.
> So it's not useful for files where you can have varying amounts of
> whitespace between the columns.
> Use awk instead:
> awk '{print $11}'

Except that awk command won't work as expected if the filename
contains whitespace.
[vbcol=seagreen] 

If all your file pathnames are absolute (start with /), why not:
sed -e 's/^[^\/]*//'
Or if they're not necessarily all absolute, but start two characters
after the end of the time/date data fields, and possibly even start
with whitespace:
perl -pe '
s/
(?:

#first field, possibly with leading whitespace
\s*\S+

#2nd through 10th fields, with leading whitespace
(?:\s+\S+){9}

#a single space:
\
#(there is a single space after that backslash)
)
//ox;
'
Of course if the file pathnames contain newlines, things may get a
bit
more interesting.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:33 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register