Generate filenames in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate filenames in a loop
# 1  
Old 02-02-2012
Generate filenames in a loop

Hi all,

I want to generate output files in a loop, run the same command on the same input file 1000 times and output in files with a new name each time, maybe a number appended to it. The output will be different each time as I`m sampling randomly from the input file.


I want to do the following in a loop.

Code:
randomsample input_file.txt > output_file1.txt
randomsample input_file.txt > output_file2.txt
...
randomsample input_file.txt > output_file1000.txt

Please help

Last edited by Franklin52; 02-03-2012 at 01:56 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 02-02-2012
Code:
while [ $cnt -lt 1000 ]
do 
  randomsample input_file.txt > output_file$cnt.txt
  ((cnt=cnt+1)) 
done


Last edited by Franklin52; 02-03-2012 at 01:56 PM.. Reason: Please use code tags for data and code samples, thank you
This User Gave Thanks to 47shailesh For This Post:
# 3  
Old 02-02-2012
Here's a way using a for loop in ksh93 on Solaris:
Code:
#!/usr/dt/bin/dtksh

CTR=1001

for (( i=1;i<$CTR;i++ ))
do
  randomsample input_file.txt > output_file${i}.txt
done

exit 0

# 4  
Old 02-02-2012
That works fine in BASH too.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing FileNames

Hi, Its been a long time since I've done any shell scripting and I need some help here. Thanks in advance... I need this as a bourne or csh script running under SCO. In a folder I have a list of Backup files named with "TarBackup plus a date and time component suffix" like this; ... (2 Replies)
Discussion started by: stanlyn
2 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies

4. Shell Programming and Scripting

How to use perl to generate files with correct filenames?

Hi, I'm trying to use perl to generate files based on sections in a large textfile. This will create one file per section that starts with " ABC_": perl -n -e '/^ABC_/ and open FH, ">output_".$n++; print FH;' largefile.txt However, the output filenames will be on the form output_nn. This... (2 Replies)
Discussion started by: Yagi Uda
2 Replies

5. Shell Programming and Scripting

For loop with dashes in filenames causing weird output

Hi again, What i'm trying to accomplish here is search a large directory for certain filesames, read from a txt file and looping through it. For instance, one of my target names from the loop file is: 1ad55f47-c342-496b-a46d-ba7de0f1b434 My loop is constructed thusly, run in a directory... (2 Replies)
Discussion started by: Karunamon
2 Replies

6. Shell Programming and Scripting

Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file. I've found a bash script that works, except that it can't handle whitespace in the filenames. #!/bin/bash if ; then echo "Usage: searchodt searchterm" exit 1 fi for file in $(ls *.odt); do ... (4 Replies)
Discussion started by: triplemaya
4 Replies

7. Shell Programming and Scripting

loop through numbered filenames

Hi I'm very new to this script thing, so please be gentle. I am trying to get a command - the mach2qtl command in the code below - to loop through a set of files. Each command should take the same two .dat and .ped files, but the .mlinfo and .mlprob files with filenames including 'chrom1' ... (7 Replies)
Discussion started by: polly_falconer
7 Replies

8. UNIX for Dummies Questions & Answers

extracting and using date from filenames in a loop

HIya, Having a dumb day whilst writing an archive process in Shell want to extract from the filename the date and archive into tar files based on this, I don't want to use mtime as it may not be the actual file date. The files are -rw-rw---- 1 user admin 100 Aug 29 11:10... (2 Replies)
Discussion started by: badg3r
2 Replies

9. Shell Programming and Scripting

Patterns in Filenames

Hi, To start, I am using a bash shell on a G4 powerbook running Leopard. I am attempting to write a shell script that will automate the processing of satellite imagery. All the filenames are of the following construction: A2008196000500.L2 where A indicates the sensor, the next four... (6 Replies)
Discussion started by: msb65
6 Replies

10. Shell Programming and Scripting

changing filenames in a directory to a number within a loop

hey guys. i'm new to shell scripting but not new to programming. i want to write a script that will take all the files in the current directory that end with a particular filetype and change all their names to a number in order. so, it would take all the jpg files and sort them in alphabetical... (30 Replies)
Discussion started by: visitorQ
30 Replies
Login or Register to Ask a Question