Home » Infrastructure » Unix » Unix Cut command
Unix Cut command [message #98170] Tue, 20 April 2004 22:14 Go to next message
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 #98172 is a reply to message #98170] Wed, 21 April 2004 03:06 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Hi,

Try the following:

ls -l | awk '{print $1 " " $3 " " $8 }' 


Best regards

Frank
Re: Unix Cut command [message #98181 is a reply to message #98170] Thu, 22 April 2004 12:27 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 #98433 is a reply to message #98170] Mon, 04 October 2004 01:07 Go to previous messageGo to next message
Jess
Messages: 3
Registered: March 2002
Junior Member
Hi,

Try this ls -l&#124cut -d' ' -f1-5
Re: Unix Cut command [message #98533 is a reply to message #98433] Mon, 20 December 2004 18:45 Go to previous message
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
Previous Topic: how to execute a stored procedure in unix
Next Topic: Question on AT command
Goto Forum:
  


Current Time: Fri Mar 29 07:20:54 CDT 2024