If function to search for files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers If function to search for files
# 1  
Old 10-04-2011
If function to search for files

Hi,
I need to concatenate two files as long as both files are present. As of now, I am using the following code:
Code:
#!/bin/bash
for y in {1..14}
do
	cat -s $y.F $y.R > $y.1
done

However, the outputfile is being generated even in the absent of both infiles. I would like to search for both infiles first and then cat them if the are present. If not I should move to the next pair of files. I though that using an IF statement will do it but I am not quite sure how to make it work:
Code:
#!/bin/bash
for y in {1..14}
do
	if [ "${y}" == $y.F ] # I need to modify this section so I can look for both files y.F and y.R
	then
		cat $y.F $y.R > $y.1
	fi
done

Of course, the scrip above is not working. I will be very thankful if someone can help me correct the script or suggest a better way to accomplish this task.
May be find?
Code:
find -name $y.R -exec cat $y.F '{}' \;


Last edited by Xterra; 10-04-2011 at 11:14 AM..
# 2  
Old 10-04-2011
Code:
[ -e "$y.F" -a -e "$y.R" ] && cat $y.F $y.R > $y.1 || echo "No files present"

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 10-04-2011
Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Programming

Search function help

Hello again unix.com, I need a help with a search function on the website i'm building. http://auto-nonstop.ro/index.php?page=search --> when I press Apply the search fields of the plugin pops up... all i want to do is http://auto-nonstop.ro/index.php?page=search to be the page before I press... (1 Reply)
Discussion started by: galford
1 Replies

4. Shell Programming and Scripting

search for content in files. Name of files is in another file. Format as report.

Hi I have multiple files in a folder and one file which contains a list of files (one on each line). I was to search for a string only within these files and not the whole folder. I need the output to be in the form File1<tab>string instance 2<tab> string instance 2<tab>string instance 3... (6 Replies)
Discussion started by: pkabali
6 Replies

5. SuSE

Search all files based on first and in all listed files search the second patterns

Hello Linux Masters, I am not a linux expert therefore i need help from linux gurus. Well i have a requirement where i need to search all files based on first patterns and after seraching all files then serach second pattern in all files which i have extracted based on first pattern.... (1 Reply)
Discussion started by: Black-Linux
1 Replies

6. UNIX for Dummies Questions & Answers

How to find function name based on word search

Hi All, I want to find out function name based on word. Here i ll give u one example I have several files based on below format. file will start and ends with same name only EX: file1.txt public function calculate1() { ---- ---- call Global Function1() ---- ---- } END... (9 Replies)
Discussion started by: spc432
9 Replies

7. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

8. UNIX for Advanced & Expert Users

Search files with specfic extention and later search content

Hi, I would appriciate if somebody can help me figure out how to search for all the *.xml file under a specific directory and subdirectroies (/home/username) and later search of content "<start>" inside the xml file returned by search. -Lovin.V (2 Replies)
Discussion started by: lovi_v
2 Replies
Login or Register to Ask a Question