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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 07:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 09:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 05:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 10:44 PM

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 05-29-2007
rinku rinku is offline
Registered User
  
 

Join Date: May 2007
Posts: 54
Unhappy ls command

I want to print only the name of one file which is last modified.
I use ::

$ls -ltr S07* |cut -f 8-9

but it is not working.

it gives the outut

-rw-r--r-- 1 aaaaa aaaaa 0 May 29 00:32 S070528D
-rw-r--r-- 1 aaaaa aaaaa 0 May 29 00:41 S070528S

I want the output

S070528S

please help me.
  #2 (permalink)  
Old 05-29-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
ls-command-here | awk '{print $NF}'
  #3 (permalink)  
Old 05-29-2007
rinku rinku is offline
Registered User
  
 

Join Date: May 2007
Posts: 54
Unhappy

I could not understand.
Please explain what is "ls-command-here" and what is "$NF"
please tell.
  #4 (permalink)  
Old 05-29-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
ls-command-here is your ls command. Replace "ls-command-here" and put your ls command there

"print $NF" tells awk to print the field that is referenced by the total number of fields. i.e. if your ls output has 9 fields, NF will be 9, and hence $NF will print field 9 - the last field.

Cheers
ZB
  #5 (permalink)  
Old 05-29-2007
rinku rinku is offline
Registered User
  
 

Join Date: May 2007
Posts: 54
thanx.
it works but it print All file name which are similar to that pattren.
that means it print
S070528D
S070528S

both file name. but I want to print only last modified file name.
If I have to change that ls command then plz tell me what is it.
  #6 (permalink)  
Old 05-29-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
ls-command-here | sed -n '$p' | awk '{print $NF}'

sed -n '$p' tells sed not to print anything (-n) except what is explicitly requested, and that is to print (p) the last line ($).

Cheers
ZB
  #7 (permalink)  
Old 05-29-2007
praveenkumar_l's Avatar
praveenkumar_l praveenkumar_l is offline
Registered User
  
 

Join Date: May 2007
Posts: 36
Quote:
Originally Posted by rinku
I want to print only the name of one file which is last modified.
I use ::

$ls -ltr S07* |cut -f 8-9

but it is not working.

it gives the outut

-rw-r--r-- 1 aaaaa aaaaa 0 May 29 00:32 S070528D
-rw-r--r-- 1 aaaaa aaaaa 0 May 29 00:41 S070528S

I want the output

S070528S

please help me.
Try this

ls -1 |tail -1

NOTE: ls option is not l (el), but 1 (one)
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 12:24 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