Find a path of a specific file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a path of a specific file
# 1  
Old 10-29-2008
Find a path of a specific file

Hi,

A variable value is /home/samir/datas/data.txt
I want /home/samir/datas.
How can I get that.
# 2  
Old 10-29-2008
Could you explain it?

Provide some more information about what exactly you want? I didn't get what your asking..
# 3  
Old 10-29-2008
The exact path of data.txt i.e. /home/samir/datas/data.txt
is stored in a variable.

I want /home/samir/datas i.e. path not includes the filename
to estract and store into another variable.

Simply I want to cut /home/samir/datas from /home/samir/datas/data.txt
# 4  
Old 10-29-2008
Can anyone help me
how to extract /home/samir/datas
from /home/samir/datas/data.txt
# 5  
Old 10-29-2008
Hope ...this will work out

echo $TMPVAR | awk -F / '{ for (i=1;i<NF;i++) printf $i"/"; }'

Where TMPVAR contains the path of the file.
# 6  
Old 10-29-2008
Quote:
Originally Posted by samir_standing
Can anyone help me
how to extract /home/samir/datas
from /home/samir/datas/data.txt
Code:
path=$(dirname /home/samir/datas/data.txt)

# 7  
Old 10-29-2008
Code:
echo "/home/samir/datas/data.txt" | sed 's/\(.*\/\)\(.*\)/\1/'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Find command to exclude a specific path

Hi Folks, I want to run the below command and to exclude the specific path like /var/test/support/... . How to achieve using the below command find / -type f \( –perm –4000 –o –perm –2000 \) –print -Siva Please do not use FONT tags inside CODE tags. And, there is usually no reason to... (2 Replies)
Discussion started by: gsiva
2 Replies

2. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

3. Shell Programming and Scripting

How to retrieve a file from specific path using unix script?

Hi i'm new to shell script, i want to get the filename from specific location which i mentioned in my script. The scirpt should read the filename exactly using the following command "ls -ltr | tail -1". Could someone show me on this. Below is my script #!/bin/ksh PATH= /usr/ if then ... (4 Replies)
Discussion started by: fresher
4 Replies

4. Shell Programming and Scripting

How to a find a file in which path it is there?

Hi Firends, Good Morning to all, I want a find command to search a paticular file present in my system(ie search through under all users and all directories.) I am looking forward from you.:) Advance Thanks, Siva Ranganath CH (3 Replies)
Discussion started by: sivaranga001
3 Replies

5. UNIX for Dummies Questions & Answers

Find unix path to a file?

I know this is very newbie ... but I need help determining the proper file path to file...Have no idea how to do this I'm on a Mac OS X 10.6 Snow Leopard thanks very much (4 Replies)
Discussion started by: jmarc
4 Replies

6. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

7. Shell Programming and Scripting

how to find the path of a file?

Hi all, Is there any way to find the the path of a file? I mean executable files and just anyother file we can think of? i know of one cmd called which $which mount /usr/bin/mount this is fine, but "mount" is a cmd not a file that can be searched eg: say i have created a text file... (3 Replies)
Discussion started by: wrapster
3 Replies

8. UNIX for Dummies Questions & Answers

command to find the path of a file

What is the command to find the path of a file if we know the file name and the root directory where the file resides.. For eg. if a file abc.dat resides in /home/mydir/myfiles/. I am looking for a command which will be fired from / directory, takes abc.dat as input and display the path of... (3 Replies)
Discussion started by: abhilashnair
3 Replies

9. Shell Programming and Scripting

to find the file with full path

Hi, I have written this shell script: fl=`ls -1lrt $mylist | grep '\.xml$' | awk '{print $9}'` echo $fl (1) for i in $fl do for dir in $mylist do if then echo $dir/$i >> tmp (2) fi done done The mylist contains some directory names. The satement (1) gives the sorted list... (5 Replies)
Discussion started by: surjyap
5 Replies
Login or Register to Ask a Question