12-09-2009
Looping through 2 files simultaneously
Hi all,
I'm having a problem with a script which should ultimately provide a filename by reading a value from file1 and file2 then join together.
I'm planning to use a loop/ loops to get the values out of both files and create a single string unfortunately the code currently treats the second loop (which is how I have written it to be fair) as nested instead of working simultaneously. The thing is that my sanity is slowly slipping away so I have stripped the code back to try and get a clearer picture.
The file's contain:
num.txt
65
65
66
67
first.txt
MRO0122
MRO0112
MRO0112
MRO0113
Currently the code returns:
MRO011365
MRO011365
MRO011366
MRO011367
What I want is
MRO012265
MRO011265
MRO011266
MRO011367
Anyway here's the code:
for update in `cat num.txt`
do
echo $update
for filename1 in `cat first.txt`
do
echo $filename1
truefile=$filename1$update.TXT
done
echo $truefile
doneLet me know if this is post is confusing in it's description and i'll try to provide clearer detail.
Any help will be thoroughly appreciated
I'm off to shoot myself.
Thanks
Chris
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Okay...
I've solved one problem.
Here's the next.
I'm writing a script file that needs to go through a directory and list all files in that directory.
I'm using TCL/TK.
I figured out how to go through the directory and how to loop through it, but I ran into a little problem.
... (2 Replies)
Discussion started by: kapolani
2 Replies
2. Shell Programming and Scripting
Say I have 2 files of 2 rows of 3 columns each
file1:
cat catdata1 catdata2
dog dogdata1 dogdata2
file2:
cat catdata3 catdata4
dog dogdata3 dogdata4
and I need to combine both files so that is appears like:
cat catdata1 catdata2 catdata3 catdata4
dog dogdata1 dogdata2 dogdata3... (8 Replies)
Discussion started by: Awanka
8 Replies
3. Shell Programming and Scripting
I posted this in the Solaris forum, but I don't think it's platform specific, so I'm posting it here.
Here is the situation. We are a company that has been using a professional publishing system, the software is called "ProType". It runs on Solaris 2.4, however it is no longer supported and we... (6 Replies)
Discussion started by: Fred Goldman
6 Replies
4. Shell Programming and Scripting
I can't get touch to simultaneously create three empty files file1, file2, file3. I tried:$ touch filebut all I got was one file:$ fileWhat did I do wrong? (4 Replies)
Discussion started by: na5m
4 Replies
5. Shell Programming and Scripting
Hi,
I am having issue where I have to tail 3 log files continuously (forever) and while I am reading the files , parse them and shove the data into DB. I can do this with one file totally fine but how can I read 3 files at the same time? I am not really looking for code (but would be nice) but... (3 Replies)
Discussion started by: Dabheeruz
3 Replies
6. Shell Programming and Scripting
Hi ,
I have a large no of files which all end in .asp.htm extension .
But for proper navigation between the pages I need to rename all those files as .asp only .
How can it be done ? (4 Replies)
Discussion started by: nshailesh
4 Replies
7. Shell Programming and Scripting
I am writing a ksh which has to load 7 files(.dat files) from input directory into oracle tables using sql loader. The process has to take each file at a time and once if it is loaded succesfully using sql loader into oracle tables then the process has to pick next file and load it into oracle... (2 Replies)
Discussion started by: vpv0002
2 Replies
8. UNIX for Dummies Questions & Answers
Does anybody know how to make symbolic links for multiple files simultaneously?
Often times I need make symbolic links for multiple files with some common pattern (just like "*.jpg"). Is there a way to avoid making symbolic link for each of them one by one...
Thank you! (6 Replies)
Discussion started by: danieladna
6 Replies
9. Shell Programming and Scripting
Hello,
Is it possible to handle data from two different files at once in awk (latest version and platform is Fedora). I found on the net that we cannot nest awk. My requirement is that I have two similar files :
File 1:
Name: abc
Val = 58
Name: cdf
Val = 1;
..................
File... (7 Replies)
Discussion started by: fifteate
7 Replies
10. Shell Programming and Scripting
dear all,
i'm preparing a script which can do these actions :
1. stop remove server's certain service
2. clean the files on remote servers simultaneously (because lots of files need to be deleted)
3. after files/logs are removed, restart the service again
i'm stuck on how to clean remote... (4 Replies)
Discussion started by: tiger2000
4 Replies
LEARN ABOUT DEBIAN
combine
COMBINE(1) COMBINE(1)
NAME
combine - combine sets of lines from two files using boolean operations
SYNOPSIS
combine file1 and file2
combine file1 not file2
combine file1 or file2
combine file1 xor file2
_ file1 and file2 _
_ file1 not file2 _
_ file1 or file2 _
_ file1 xor file2 _
DESCRIPTION
combine combines the lines in two files. Depending on the boolean operation specified, the contents will be combined in different ways:
and Outputs lines that are in file1 if they are also present in file2.
not Outputs lines that are in file1 but not in file2.
or Outputs lines that are in file1 or file2.
xor Outputs lines that are in either file1 or file2, but not in both files.
"-" can be specified for either file to read stdin for that file.
The input files need not be sorted, and the lines are output in the order they occur in file1 (followed by the order they occur in file2
for the two "or" operations). Bear in mind that this means that the operations are not commutative; "a and b" will not necessarily be the
same as "b and a". To obtain commutative behavior sort and uniq the result.
Note that this program can be installed as "_" to allow for the syntactic sugar shown in the latter half of the synopsis (similar to the
test/[ command). It is not currently installed as "_" by default, but you can alias it to that if you like.
SEE ALSO
join(1)
AUTHOR
Copyright 2006 by Joey Hess <joey@kitenet.net>
Licensed under the GNU GPL.
moreutils 2012-04-09 COMBINE(1)