Unix Cut command [message #98170] |
Tue, 20 April 2004 22:14 |
Prajakta Pillai
Messages: 1 Registered: April 2004
|
Junior Member |
|
|
I am a new user to unix and stuck with a problem.
In ls -l command I want 3 columns to be displayed. They are Permissions, author and file name. I think I have to do ls -l and pipe the output to cut command.
Something like
ls -l | cut -d " " -f1,3,8
My problem is I dont know what should I give in delimiter in this case
Can anybody pls hep me regardsin this
Thanks
Prajakta
|
|
|
|
Re: Unix Cut command [message #98181 is a reply to message #98170] |
Thu, 22 April 2004 12:27 |
jan
Messages: 71 Registered: August 2002
|
Member |
|
|
you can use tr to remove extra space and use single space as delimeter.
e.g.
$ ls -l | tr -s " "| cut -f1,3,8 -d" "
hope this helps
Jan
|
|
|
Re: Unix Cut command [message #98220 is a reply to message #98170] |
Thu, 13 May 2004 13:01 |
Jake
Messages: 14 Registered: August 2000
|
Junior Member |
|
|
======================================================
Problem:
======================================================
In ls -l command I want 3 columns to be displayed. They are Permissions, author and file name. I think I have to do ls -l and pipe the output to cut command.
Something like
ls -l | cut -d " " -f1,3,8
My problem is I dont know what should I give in delimiter in this case
======================================================
Answer:
======================================================
ls -l | sed 's/ */ /g' | cut -d" " -f1,3,9
The problem is there are multiple spaces between some of the fields. To fix it, pipe the results into the sed command to convert any two or more spaces into one.
It doesn't show very well on the screen, but there are two spaces between the "'s/" and the "*/", and there is one space between the "*/" and the "/g'" .
And the file name is in field 9, not 8.
|
|
|
Re: Unix Cut command [message #98317 is a reply to message #98170] |
Tue, 20 July 2004 00:37 |
Dominique
Messages: 1 Registered: July 2004
|
Junior Member |
|
|
Use awk, if you already know which columns to diplay.
ls -l pattern | awk '{print $1 $2 $3}'
to print cols 1,2,3. awk uses the space(s) as default delimiter.
Dominique
|
|
|
|
Re: Unix Cut command [message #98533 is a reply to message #98433] |
Mon, 20 December 2004 18:45 |
VED
Messages: 2 Registered: March 2004
|
Junior Member |
|
|
Hi,
Suppose your files are delimeted by |
like
|abc|cdb|hh557788|red|green|
Then you give "|" as delimeter and f4 if you want to pick up fourth delemited word.
ved
|
|
|