Search a directory for files that contain pathnames
Hello, I really don't know if this is possible, but I figured the wonderful users of unix.com may be able to provide me with some help/suggestions.
I want to create a (bash) script that would go will accept an input file. That input file contains important information as well as pathnames. For example,
For the filler information, I need to parse (which I have already done). However, if the script sees that one of the lines is a pathname, go to that file, and repeat the process.
Therefore, file1.txt would see "path/to/file2.txt" and go to that file. File2 would then be parsed to see if it contains any pathnames etc. This repeats until no more paths are found. Is this possible?
edit- This was posted in Unix of Advanced & Expert Users by mistake. Sorry for the error!
I think you should use either a while loop to awk to figure this out since you would have to go line by line. For example, the script would look at line one. If it contains "useful" information, save it. Otherwise it's a line which contains a path. In that case, go to that file and repeat the process.
Maybe others here can be more of help. I'm just not too familiar with awk to provide a solid answer.
This the way to read line in a file ( the syntax would require proper spacing around the brackets though).. you would need to specify a pattern instead of a single slash, and does it need to have a path or could it be located in the current directory (then it would necessarily have a /)?
Also, you would need to check if the file exist and if it is readable. You could put it in a variable, but what do you need to do with it? Perhaps you only need to print it, then it would not be necessary..
What would you do if you found a new path in the file? It think a recursive function with local variables would be the way forward. That would be quite simple code and since you appear to be trying to teach yourself scripting, I would not want to spoil it for you..
Have fun,
S.
Last edited by Scrutinizer; 05-20-2012 at 06:06 PM..
Hi All,
How to search for a string in all the files irrespective of directory.
If I use grep -i 'hello' *.*
It will search for the string hello in the files of current directory.
But I want to check for the string hello in the files of all the directories.
Thanks (4 Replies)
I have ~100 text files in a directory that I am trying to parse and output to a new file. I am looking for the words chr,start,stop,ref,alt in each of the files. Those fields should appear somewhere in those files. The first two fields of each new set of rows is also printed. Since this is on a... (7 Replies)
Hello dears,
In my home directory (msc-loader) there are some files like this:
# ls -l
-rwxrwxrwx 1 user dba 1680318 Jan 20 13:32 103386_s.c
-rwxrwxrwx 1 user dba 256743 Jan 20 13:37 103387_o.c
-rwxrwxrwx 1 user dba 1635363 Jan 20 13:39 103387_s.c
-rwxrwxrwx 1 user dba 264735 Jan 20... (3 Replies)
Hi Guys,
I want to search the content of all the files (of a particular type like .txt)
in a directory for a specific string pattern. Can anyone help me?
Thanks (7 Replies)
I need to search for a particular string. This string might be present in many files. The directory in which I am present has more than one subdirectories. Hence, the search should check in all the subdirectories and all the corresponding files and give a list of files which have the particular... (5 Replies)
I was google searching and found
Perl as a command line utility tool
This almost solves my problem:
find . | xargs perl -p -i.old -e 's/oldstring/newstring/g'
I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I... (1 Reply)
Hello my friends,
I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories?
So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
hi
can i know how to get the file name of any files containing for example "abc" from a number of files in a directory?
i tried "ls -ltrc | grep abc" but no resulted generated.
thanks in advance. (1 Reply)
I wanted to search in all the sub directories under /vob/project (recurse) in everything inside /vob/project.
search.run
for x in `cat search.strings`
do
find /vob/project -type f -print | xargs grep -i $x > ~/$x.txt
done
search.string
hello
whoami
I am getting the error ... (5 Replies)