Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combine two files using awk 2

Status
Not open for further replies.

bg1980

Technical User
Feb 19, 2009
2
DE
Hi,
I am quite new to work with text-info files using awk and
I am stuck with following problem:

file one <image info> contains the following information
3001 1 5 20000 21000 2.0
3002 6 9 25000 25000 0
3003 10 14 17000 17500 0.3
...

$1 names an image
$2-$3 name image patches from the respective image$1
$4-$6 are conditions true for all image patches

I manage to create a set of files containing the patchnames within a file named like the image itself:

file <3001>: file <3002>: file <3003>: ....
1 6 10
2 7 11
3 8 12
4 9 13
5 14

But I am stuck at the point where I would need to paste in the respective information from image 3001 in file one $4-6 behind each patch number in file two.

The outcome should look as follows:

file <3001x>: file <3002x>: ....
1 20000 21000 2.0 6 25000 25000 0
2 20000 21000 2.0 7 25000 25000 0
3 20000 21000 2.0 8 25000 25000 0
4 20000 21000 2.0 9 25000 25000 0
5 20000 21000 2.0

I guess it works somehow with an awk do/while loop and grep, but wasn't able to work out how. My main problem was that the information always comes from two files, and in addition I want to "expand" my file one ...

It would be great if someone could give me a hint how to tackle this problem ... because it is far to much information to do it by hand, just something which has to be done with some logic statements.

Thanks
 
something like this ?
awk 'NF==6{f=$1"x";for(i=$2;i<=$3;++i)print $1,i,$4,$5,$6>f;close(f)}' /path/to/image_info

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
YES THAT WORKS!
Thanks, a lot ... I've tried quite a bit, but looking at this, I was still far away from the right solution.

Thanks again.
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank PHV
for this valuable post![/navy]


at the bottom of PHV's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top