LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-03-2009, 01:43 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
Cut the third colum


The below is the result of command "ls" ,

-rw------- 1 user1 sys 4983 Jun 3 14:25 ora_log1

can advise if I want to have a command ( script ) that cut the third colum of the line , what can i do ? Thx

* my expected outoput is "user1" .
 
Old 06-03-2009, 01:47 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

What you show is not the output of ls, but ls -l.

Anyway, if you want the third column from the output you show:

ls -l | awk '{ print $3 }'

Hope this helps.

PS: You might want to take a look at the ls manpage, maybe it has an option to only show the username.....
 
Old 06-03-2009, 02:06 AM   #3
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 25
Hello.

Quote:
Originally Posted by ust View Post
<..> I want to have a command ( script ) that cut <..>
Also make sure to check out the command called "cut" :-)
 
Old 06-03-2009, 02:43 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Information about files are provided by the stat command. too:
Code:
owner=$(stat -c%G $file)
 
Old 06-03-2009, 03:03 AM   #5
kunalghosh
LQ Newbie
 
Registered: Mar 2007
Distribution: suse linux 9.1,xubuntu
Posts: 29

Rep: Reputation: 15
Wink Reply to cut 3rd column

the following command will cut and give the 3rd column for you.

ls -l | cut -d " " -f 4

in case this doesnt work try playing around with -f N changing N to 3 should do the trick. read the man page for cut -- "man cut" to get a description of what was done in the code.

regards
 
Old 06-03-2009, 07:30 AM   #6
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Because ls uses tabs to format the output better in some places, you can't use just a space as a delimiter. What I usually do is pass the info through tr first, replacing all of the white space with a single space, and then do the cut.

Code:
ls -l | tr -s '[:blank:]' ' ' | cut -d' ' -f3
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql+php - table colum with multiple values? i need logic help. blancs Programming 1 12-01-2008 02:08 AM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM
Combine multiple one column text file into one text file with multiple colum khairilthegreat Linux - Newbie 7 11-23-2007 01:31 PM
Sort file based on only ONE colum smart_sagittari Linux - Newbie 6 07-08-2005 12:25 AM
ls -l second colum in output praveenv Linux - Newbie 1 08-26-2004 07:37 AM


All times are GMT -5. The time now is 12:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration