Extract directory from full file name?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract directory from full file name?
# 1  
Old 11-06-2012
Extract directory from full file name?

I think I know what this is doing, but the 'eval' is confusing

Code:
fname=$(echo ${lineItem} | awk 'BEGIN {FS=";"}{print $1}')
fname=${fname%%+([[:space:]])}
fname=${fname##+([[:space:]])}
eval "fname=${fname}"

The first line extracts the contents of the line preceeding the ";"
2nd & 3rd lines trim the value (I think .. not sure what the +([[:space:]]) does ..)
But what would be the purpose of the eval statement?

Last edited by joeyg; 11-07-2012 at 10:46 AM.. Reason: corrected spelling
# 2  
Old 11-06-2012
to get directory of file, try also:
Code:
dname=$(dirname filename)

# 3  
Old 11-06-2012
Actually, I need to know what the original code is doing, as I have to document (pseudo-code) the process. I know some basics, and can typically work out what is being done, but things like this throw me for a loop!

- Jon

PS - The authors may not have been the best coders, and if it is as simple as you indicate, then someone will modify the code!
# 4  
Old 11-07-2012
Since we have no idea what your input looks like and we have no idea what output is being produced, it is hard to guess what the author of this code intended the eval to have the shell expand for you. It may also help to know what shell you're using and what type of system you're using.
# 5  
Old 11-08-2012
The script starts with #!/bin/ksh, hopefully that helps with the shell portion. The contact that can provide the actual server mfg and Unix/Linux version is on vacation for the next few days ... :-(

The input file (aka lineitem) looks like:
/finance/reports/july_operations.gzp;120

So fname starts out as /finance/reports/july_operations.gzp

- Jon
# 6  
Old 11-08-2012
Try to run the script with the -x option set and publish the log.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

2. Shell Programming and Scripting

Extract a single file from a tar file to another directory

Hi, I need to extract a single file from a tar file to another directory. So far I have this: This one extract a single file to same directory: tar -xvf filename.tar ./file.txt I tried this but its not working tar -xvf filename.tar /home/dir ./file.txt or this: (6 Replies)
Discussion started by: erin00
6 Replies

3. Solaris

HOW TO extract.tar file to specific directory..?

Hi all, In Solaris howto extract tar file to specific folder. This is what we do in Linux, but how to do the same thing in Solaris ? -tar -xzvf /tmp/etc.tar.bz -C /tmp (Will extract in /tmp dir) 3.gzip COMPRESSION AND EXTRACTION -tar -czvf /tmp/etc.tar.bz /etc -du ... (5 Replies)
Discussion started by: manalisharmabe
5 Replies

4. Shell Programming and Scripting

extract every filename containing certain string in a directory and do some commend per file

Hi, Here is my question: suppose I have files like 1990_8xdaily_atmos.nc 1991_8xdaily_atmos.nc 1992_8xdaily_atmos.nc 1993_8xdaily_atmos.nc 1990_daily_atmos.nc 1991_daily_atmos.nc 1992_daily_atmos.nc 1993_daily_atmos.nc 1990_month_atmos.nc 1991_month_atmos.nc 1992_month_atmos.nc... (1 Reply)
Discussion started by: 1988PF
1 Replies

5. Shell Programming and Scripting

Need to extract a folder from a full path

Hi everyone, I have different folders which looks like this: /mnt/ecrm/master/ecrm/templates/brochure/de_DE/zeitlos.ott /mnt/ecrm/master/ecrm/templates/mail/en_US/default.html /templates/header_and_footer/en_US/default.txt I want to get the bold text only in a variable. I already have a... (3 Replies)
Discussion started by: evilass
3 Replies

6. Shell Programming and Scripting

How to extract strings from full path when full path is not fixed

/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR Error Message.... (0 Replies)
Discussion started by: Shirisha
0 Replies

7. Shell Programming and Scripting

Extract directory from a file path

Im trying to extract a directory from a path entered by the user Lets say the path is path=/home/bliss/files/myfile.txt i wanna extract "/home/bliss/files" from $path ... how can i do this? (4 Replies)
Discussion started by: mrudula009
4 Replies

8. Shell Programming and Scripting

find full directory and delete old dated file?

I want to write a code that will look for a particular directory which is full or more than 95% used, and will search older file and delete it. My code looks like this: df -k|while read f1 f2 f3 f4 f5 f6 do if expr '$f5' -ge '95%' || continue then echo $f5 else echo "there is no... (2 Replies)
Discussion started by: xramm
2 Replies

9. UNIX for Advanced & Expert Users

extract a sub directory form a tar file

anyone know if it is possable to extract a subdirectory in a tar file. IE tarfile contains parent dir -sub dir A -sub dir B I want to extract sub dir B. (2 Replies)
Discussion started by: Optimus_P
2 Replies

10. UNIX for Dummies Questions & Answers

extract only file name from full path file name

What is the smartest way to just extract file name from a full path name. e.g. if I have /usr/sanjay/bin/file_name.c I want only file_name.c Sanjay (2 Replies)
Discussion started by: sanjay92
2 Replies
Login or Register to Ask a Question