The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 07:05 AM
Print row if value in column 1 is the first occurence Raynon Shell Programming and Scripting 7 03-18-2008 02:31 AM
to print output using shell command cdfd123 Shell Programming and Scripting 13 08-02-2007 12:40 PM
to print column using awk cdfd123 Shell Programming and Scripting 2 07-26-2007 01:15 PM
can awk print column using a variable ?? jambesh Shell Programming and Scripting 36 09-26-2006 07:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2007
Nidhi2177 Nidhi2177 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
Smile Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All,

I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command????

Regards,
Nidhi...
  #2 (permalink)  
Old 09-14-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
tr command is used for translating characters, not for filtering columns from an output. As you said, try this:

Code:
ls -l | awk '{ print $5 }'
  #3 (permalink)  
Old 09-14-2007
Nidhi2177 Nidhi2177 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
Thanks for this prompt reply.. But I know this...

What can we use instead of 'awk' to do the same?? cut???

Regards,
Nidhi...
  #4 (permalink)  
Old 09-15-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by Nidhi2177 View Post
What can we use instead of 'awk' to do the same?? cut???

The obvious (and most sensible) command to use is awk.

You can use cut, but first you would have to pipe it through tr to remove multiple spaces:

Code:
ls -l | tr -s ' ' | cut -d ' ' -f 5
  #5 (permalink)  
Old 09-17-2007
Nidhi2177 Nidhi2177 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
Thanks All,

I have got the solution..


lines=`ls -l | tr -s [:space:] | cut -d ' ' -f 5 | wc -l`
lines=`expr $lines - 1`

echo "Fifth column of 'ls -l' command:::"
ls -l | tr -s [:space:] |cut -d ' ' -f 5 | tail -n $lines
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0