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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Extracting the first file fromf ls

Reply to Message Icon

Name: prekida
Date: July 13, 2005 at 14:38:21 Pacific
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.



Sponsored Link
Ads by Google

Response Number 1
Name: cislord
Date: July 13, 2005 at 18:06:59 Pacific
Reply:

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


0

Response Number 2
Name: prekida
Date: July 26, 2005 at 12:17:21 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Extracting the first file fromf ls

how to remove the first field www.computing.net/answers/unix/how-to-remove-the-first-field/7854.html

Extract the max no. in the File Ext www.computing.net/answers/unix/extract-the-max-no-in-the-file-ext/4485.html

shell script (first few lines mean? www.computing.net/answers/unix/shell-script-first-few-lines-mean/4326.html