![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| file size comparision local file and remote file | dba.admin2008 | Shell Programming and Scripting | 4 | 11-13-2008 05:57 PM |
| Reading a file and writing the file name to a param file. | thebeginer | UNIX for Advanced & Expert Users | 1 | 10-05-2007 05:38 PM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 05:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Getting file name ?
Assuming /dir1/dir2 has two file
file1 file2 If I get the file name which includes the dir name using command file_name=`ls -ltr /dir1/dir2/* | grep '^-' | tail -1 | awk '{print $9}' ` then I get file_name which includes the /dir1/dir2 also. if I want to get just the filename which should be file1 or file2 then how can I do that? |
|
||||
|
That worked
This Worked.
file_name=`ls -ltr /dir1/dir2 | grep '^-' | tail -1 | awk '{print $9}' ` >> I wouldn't use four external commands just the get a filename >> Is there an alternate to just get the latest file name from a dir? I used grep to just get files from a dir or skip the dirs underneath it, tail -1 gives the latest file name. Awk just prints the name. Thanks. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|