Computing.Net > Forums > Unix > Extracting the first file fromf ls

Extracting the first file fromf ls

Reply to Message Icon

Original Message
Name: prekida
Date: July 13, 2005 at 14:38:21 Pacific
Subject: Extracting the first file fromf ls
OS: Sun Solaris
CPU/Ram: 8/16G
Comment:

I need help in extracting first file only from an ls command
and store it in a local variable
I thought using awk we could build something - not very
familiar how to do it

Something like
ls -t $search_string and store the resultant
first file alone into a local variable ( as my result will have
multiple files )

Please help.
Thank you very much.


Report Offensive Message For Removal


Response Number 1
Name: cislord
Date: July 13, 2005 at 18:06:59 Pacific
Subject: Extracting the first file fromf ls
Reply: (edit)

You can do this several ways:

MY_VARIABLE=$(ls -t search_string | head -1)

or

ls -t search_string | head -1 | read MY_VARIABLE

or

MY_VARIABLE=`ls -t search_string | head -1`


Good luck


Report Offensive Follow Up For Removal

Response Number 2
Name: prekida
Date: July 26, 2005 at 12:17:21 Pacific
Subject: Extracting the first file fromf ls
Reply: (edit)

Thank you very much for your answers.
Greatly appreciate your help cislord.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Extracting the first file fromf ls 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software