![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to find a string in a directory/sub-directory | gross | UNIX for Dummies Questions & Answers | 3 | 11-13-2008 04:45 PM |
| Find a string under a directory that is contained in another file | BMC | Shell Programming and Scripting | 3 | 09-17-2008 01:41 PM |
| find and replace string in a directory files | koti_rama | Shell Programming and Scripting | 2 | 05-30-2008 03:48 AM |
| Appending a string to all files in a directory | ragavhere | Shell Programming and Scripting | 1 | 04-28-2008 06:31 AM |
| searching for a string in directory | warrend | UNIX for Dummies Questions & Answers | 4 | 09-27-2002 08:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How To Get The String Right After the Directory Name
i have this basic line of code that accepts for an input parameter. Example of input string is "/u02/app/ccalloc/dev/out/*.txt", a directory name with a wild card filename. my code below can get the directory name by using the `dirname $p1` command. when i attempted to use the `basename $p1` to get the filename with wild card character it failed.
Code:
$ sh sample.sh "/u02/app/ccalloc/dev/out/*.txt" Usage: basename String [Suffix] the directory is /u02/app/ccalloc/dev/out the file string is $ Code:
#!/bin/sh p1=$1 pdir=`dirname $p1` pfile=`basename $p1` echo "the directory is $pdir\n" echo "the file string is $pfile\n" |
|
||||
|
Do you have more than one .txt file in that directory?
By quoting this "/u02/app/ccalloc/dev/out/*.txt" all text files will become $1 to the script. Basename can only handle one file at a time. Either unquote the argument so basename can use the first one, or use a loop to process all of the .txt files: Code:
for FILE in $@; do basename "$FILE" done |
|
||||
|
great that works. i need to add a second parameter when i added a second parameter it appears that it is also including the second parameter string.
Code:
$ sh sample.sh "/u02/app/ccalloc/dev/out/*.txt" "/export/home/ccalftdv/data" EATVDAILY02132008.txt EATVDAILY03292007.txt EATVDAILY04082008.txt EATVDAILY05012008.txt EATVDAILY05282008.txt EATVDAILY06052007.txt EATVDAILY06062007.txt EATVDAILY06192009.txt EATVDAILY06222009.txt EATVDAILY06242009.txt EATVDAILY07132009.txt EATVDAILY07142009.txt EATVDAILY07152009.txt EATVDAILY07162009.txt EATVDAILY10212009.txt PCARDDAILY07102009.txt citicc_pre_pack.txt data $ |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|