to find the file with full path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to find the file with full path
# 1  
Old 10-11-2005
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 [ -f $dir/$i ]
then
echo $dir/$i >> tmp (2)
fi
done
done

The mylist contains some directory names. The satement (1) gives the sorted list of files from multiple directories. the satement (2) lists the same files with their full path. But here I get some duplicate lines in tmp file when two files with same name in different directories. Due to some condition I have no clue to remove the duplicate entries bcoz it is unknown that which entry should be removed. The above script works fine if there is no multiple file ahving same name.
I have written the above code to find the list of files from multiple directories which are sorted by the time of their creation irrespective of directories.
so please tell is there any other way to do the same thing.
# 2  
Old 10-11-2005
Quote:
Originally Posted by surjyap
the satement (2) lists the same files with their full path. But here I get some duplicate lines in tmp file when two files with same name in different directories. Due to some condition I have no clue to remove the duplicate entries bcoz it is unknown that which entry should be removed. The above script works fine if there is no multiple file ahving same name.
As far as I understand, you want to remove the duplicates files which have different paths.

Look at this thread.

Removing duplicate files from list with different path

vino
# 3  
Old 10-11-2005
No I cannt remove the duplicate entries from the list which have the same path. Because I dont know to remove which entry. Bcoz according to this entry some manipulation are being done. ok I am attatching the out put here:
For the satement (1) .......
test.xml test1.xml sample.xml tst2.xml test3.xml mvtest.xml mvtest.xml neha.xml
for the satement (2)..........
/backup/surjya/mdbase/test.xml
/backup/surjya/mdbase/test1.xml
/backup/surjya/test/sample.xml
/backup/surjya/test/tst2.xml
/backup/surjya/test/test3.xml
/backup/surjya/mvfile/mvtest.xml
/backup/surjya/test/mvtest.xml
/backup/surjya/mvfile/mvtest.xml
/backup/surjya/test/mvtest.xml
/backup/surjya/mvfile/neha.xml

The above output shows that it has 10 entries where as it should have 8 entries. At this stage we dont know which entry shoulsd be removed.
So please tell me is there any other way to find the sorted file list with full path accros the directories.
# 4  
Old 10-11-2005
Quote:
Originally Posted by surjyap
No I cannt remove the duplicate entries from the list which have the same path. Because I dont know to remove which entry.
...
The above output shows that it has 10 entries where as it should have 8 entries. At this stage we dont know which entry shoulsd be removed.
So please tell me is there any other way to find the sorted file list with full path accros the directories.
If you want to remove the duplicate entries look at Jim's solution in Removing duplicates

vino
# 5  
Old 10-14-2005
Still I have the same problem

Hi
Still I have same problem. Is it possible to find list of files in the order of their time of creation accross the directories.
We acn use "ls -rt" to find the list of files from the working dorectory. to get the list of files in certain order I used the command:
ls -rt $dir1 $dir2 $dir3 | grep '\.xml'
But here I face the problem. It works fine and gives the list of files in the certain order accross the directories. But consider very recently I created a ".xml" file in the $dir2 directory. The whole list for $dir2 comes to the end of the list. Please solve this problem
# 6  
Old 01-18-2008
I found this while searching for fast filename expansion ideas.

I know this is very old message, but thought it should be put to a close.
Here is one way to achieve the result.

ls -rt $dir1/*.xml $dir2/*.xml $dir3/*.xml

This will sort files from all directories matching "*.xml", with the oldest first.
If your directory list is a variale list then you may try the following.
Assuming input variable as "IN_VAR" containing list of dirs.

DIR_LIST=`echo $IN_VAR | sed 's, ,/*.xml ,g; s,,$/*.xml,'`

echo "$DIR_LIST"

ls -rt $DIR_LIST
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace the path value in files, pattern is not full known.

Hi, I need to do find and replace, but the pattern is not full known. for example, my file has /proj/app-d1/sun or /data/site-d1/conf here app-d1 and site-d1 is not constant. It may be different in different files. common part is /proj/xx/sun and /data/xxx/conf i want to find where ever... (6 Replies)
Discussion started by: rbalaj16
6 Replies

2. Linux

How to print full path name along with file extension?

Hi I have a requirement like this: /abc/a/x.txt /abc/a/y.txt /abc/b/x.gz /abc/b/y.txt I need output like this: /abc/a:*.txt /abc/b:*.txt /abc/b:*.gz I have tried find /abc -type f -name "*.*" ||awk -F . '{print $NF}' it is print only extensions without path name. Please... (5 Replies)
Discussion started by: lijjumathew
5 Replies

3. Shell Programming and Scripting

Grep File Full Path in a file

Hi, I would like to know how to grep all the paths in a file having extension .BMP For e.g. File Name : sample.txt File Content : xxxxxxxxxxxxxxxxx xxxxx/root/cdrive/picure.BMP xxxx xxxxxxxxxxx xxxxx/root/ddrive/picure.BMP xxxx xxxxxxxxxxx Expected Output : ... (4 Replies)
Discussion started by: vdivb
4 Replies

4. 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

5. Shell Programming and Scripting

Return Full File Path To Array PERL

Iam trying to load the full path of multiplie files in the same directory to an array if the filenames matches a pattern. The following is the current code; where $input=C:\test # change to and open the comparison directory chdir("$input2") || die "Cannot change dir: $!"; opendir(DIR2,... (2 Replies)
Discussion started by: cold_Que
2 Replies

6. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

7. Shell Programming and Scripting

list file with full path

This has been bugging me for a while. How can i list file to show full path. /directory/test $ ls file.tst file.tst $ desired output: /directory/test/file.tst (2 Replies)
Discussion started by: ryandegreat25
2 Replies

8. UNIX for Advanced & Expert Users

list all files with full path of the file

How can i list every single file on a sun solaris server running 2.8 starting from '/' with the full path included in it? example. / ... ... ... /etc/inetd.conf /etc/passwd /etc/shadow ... ... ... /var/adm/messages /var/adm/messages.0 /var/adm/messages.1 ... ... ...... (4 Replies)
Discussion started by: Sowser
4 Replies

9. UNIX for Advanced & Expert Users

process executable file full path

hi guys i give "ps -ef | grep some_executable_file" on the command line. this "some_executable_file" resides on many paths which r included in the PATH environment variable, so the output depicts only "some_executable_file" in the COMMAND column. how can i get the full path? thanx (3 Replies)
Discussion started by: xtrix
3 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