The UNIX and Linux Forums  

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 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 03:05 AM
Print row if value in column 1 is the first occurence Raynon Shell Programming and Scripting 7 03-17-2008 10:31 PM
to print output using shell command cdfd123 Shell Programming and Scripting 13 08-02-2007 09:40 AM
to print column using awk cdfd123 Shell Programming and Scripting 2 07-26-2007 10:15 AM
can awk print column using a variable ?? jambesh Shell Programming and Scripting 36 09-26-2006 04:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-14-2007
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...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-14-2007
robotronic's Avatar
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 }'
Reply With Quote
  #3 (permalink)  
Old 09-14-2007
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...
Reply With Quote
  #4 (permalink)  
Old 09-15-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 713
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
Reply With Quote
  #5 (permalink)  
Old 09-17-2007
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0