Visit The New, Modern Unix Linux Community

Naming output files based on variable parameters and input filenames

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Naming output files based on variable parameters and input filenames
# 1  
Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like ATd, PZa, RTK1, so I want to end with files like AG005574_ATd, AG005574_PZa, AG005574_RTK1, AG004788_ATd, etc.
I loop through the subfolders, run the process and output the results like so:
for file in $(find /path/to/files/AG00*/*/ -type f -name 'AG00*.fa');
 do process --out=$output."tab" <options> $file ;
      echo $file

Obviously, this names the file by process only, not by process_input, and it only writes one file (the last processed) because it over-writes the others. In the case above, the --out= seems to me to be the key to change to get what I want, but $output$file and variations don't work.
I'm sure this is not a tricky problem but I haven't been able to find or piece together a solution. Any help/tutoring is much appreciated.

Moderator's Comments:
Mod Comment select text first before clicking code button

Last edited by Scrutinizer; 01-12-2015 at 02:40 PM.. Reason: repaired code tags
# 2  
output=$file is empty.
That is because it is outside the loop, try to place it 2 lines lower.
Therefor both, the current and your 'future' line:
 do process --out=$output."tab" <options> $file ;

Looks in plaintext:
 do process --out=."tab" <options> Value_from_Find ;

Or at best (with the thought change):
 do process --out=Value_from_Find."tab" <options> Value_from_Find ;

For the moment, try:
for file in $(find /path/to/files/AG00*/*/ -type f -name 'AG00*.fa');
 do output=$file
      process --out=$output."tab" <options> $file ;
      echo $file

Hope this helps

model=1 is not used and could be deleted.
# 3  
Thanks, Sea.

I should have been more explicit about why I used


in the <options> for the process I run, I point to several different models for processing, like so:

process --out=$output."tab" /path/to/input/models/$1.hmm $file;

so that when I have

--out=$model."tab" I get part of the filename I want for my output (namely, the model I used) but not the name of the input file that was processed, and each new file that is processed over-writes the previous.

when I try something like




the process/program errors. The solution you suggested also causes an error message from the program, "no such option --tblfp", which makes no sense to me.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #28
Difficulty: Easy
Unix was the first fully supported 64-bit operating system for personal computers.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. Shell Programming and Scripting

Merge input from two files into one based on conditions

Using Linux (bash), I have two files which contain information about berries. Example: file1.txt: Blueberry blue 14 Raspberry red 12 Blackberry dark 4 file2.txt Blackberry sour 4 3 Blueberry tasty 12 78 Strawberry yummy 33 88 I want to merge these two files into one. The desired... (5 Replies)
Discussion started by: Zooma
5 Replies

3. UNIX for Dummies Questions & Answers

Split files based on user input

Hi All, I have a UNIX script which reads "PxyType" (read PxyType) as input from user and a file (eg : "File.json") with the list all PxyType's. Based on the user input for "PxyType" in "File.json", I want to redirect each matched line to a different file ("File1,2,3,..json"). Can you... (7 Replies)
Discussion started by: Deena1984
7 Replies

4. Shell Programming and Scripting

[Solved] Multiple input files and output files

Hi, I have many test*.ft1 files to which I want to read as input for a script called pipe2txt.tcl and print the output in each separate file. For example, pipe2txt.tcl < test001.ft1 > test001.txt How can I read many files in this maner? thank you very much, Best, Pahuja (5 Replies)
Discussion started by: Pahuja
5 Replies

5. Shell Programming and Scripting

Split a file into multiple files based on the input pattern

I have a file with lines something like. ...... 123_start ...... ....... 123_end .... ..... 456_start ...... ..... 456_end .... ..... 789_start .... .... 789_end (6 Replies)
Discussion started by: abinash
6 Replies

6. Shell Programming and Scripting

Complex overlap and naming of 2 input files - Awk

for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2. Specify names based on output. ####### if middle value is missing name them "SE" if first value is missing name them "AFE" if last value is missing name them "ALE" if 2 middle values are... (1 Reply)
Discussion started by: ruby_sgp
1 Replies

7. Shell Programming and Scripting

tar cmd how many arguments into parameters of filenames

Hi I would like to use tar cmd in my script. I have a variable with filenames, e.g. 1000 records and I would like to paste its values into tar cmd. For this example I used three elements variable strings. strings="file1.txt file2.txt file3.txt" `tar cf file1.tar $strings` Whether... (1 Reply)
Discussion started by: presul
1 Replies

8. Shell Programming and Scripting

Dynamic naming based on file content

I was just thinking if there is a way where i can dynamically rename files based on the actual file content. I have a load of pdf's which have been named wrongly. (We normally put date first, then brief description, then title) So can a script be written wherin, it pulls out the date and title... (2 Replies)
Discussion started by: deaddevil
2 Replies

9. Shell Programming and Scripting

create diffrent files based on other file and parameters list

I would like ot create shell script/ bash to create diffrent files based on a file and parameters list. Here is the detail example: I have a textfile and four static parameter files (having ?'). mainfile.txt has below records (this count may be more than 50) A200001 A200101 B200001... (9 Replies)
Discussion started by: raghav525
9 Replies

10. Shell Programming and Scripting

Splitting a file based on some condition and naming them

I have a file given below. I want to split the file where ever I came across ***(instead you can put ### symbols in the file) . Also I need to name the file by extracting the report name from the first line which is in bold(eg:RPT507A) concatinated with DD(day on which the file runs). Can someone... (1 Reply)
Discussion started by: srivsn
1 Replies

Featured Tech Videos