unix noob help with awk?

Hi
I'm really new to this so sorry if this is trivial

What I'm trying to do is take a file with 3 columns of numbers and cat all the entries of the second and third columns which have the same entry in the first column into a file with the number from the first column in the name. So say

1 3 4
1 3 5
1 4 6 > something1.txt

2 3 5
2 5 7 > something2.txt

Tried using awk but I'm not very good :frowning:

for i in 1 2 3 4 5 6 7 8 9 0; do cat file | egrep "^$i" >$i ; done

As an aside, cat file | egrep pattern is better expressed as egrep pattern file, without the cat.

With awk (input file is read only once) :

awk '{print > "something" $1 ".txt"}' inputfile

Jean-Pierre.

Brilliant! :cool: Works like a dream

And if I wanted to use the input filename in the output file's names? How owuld I do that?

I have the whole thing in a big script:

cat listoffilenames | while read line; do awk{the stuff above but also want the $line name in here too but it doesnt evaluated $line for me, instead prints $line} $line

Basically what I am asking is

How do I get this to work:

awk '{print > "something$inputfile" $1 ".txt"}' $inputfile

?

I've tried
awk '{print > "something"$inputfile"" $1 ".txt"}' $inputfile

But doesnt work?

Something like:

awk '{print > "something" FILENAME ".txt"}' $line

Regards

Im afraid that doesnt work.

cat listoffiles | while read $line;do awk '{print > "nonav$line" $1 ".txt"}' $line;done

This is my line.

What I want to do is take each filename in listoffiles use awk to extract the 2nd column and 3rd column of my data which have the same entry in the first column and put them in a file containing the same name as the file from which they came.

I've missed something, try this:

awk '{print > "something" FILENAME $1 ".txt"}' $line

Regards

That doesnt work either.

All Im trying to do is really

awk '{print > "something${f}" $1 ".txt"}'

How do I expand the variable ${f} inside the awk ????

Its ok, I solved it, thats for your help :b: