Hi there,
Firstly apologies, I am completely new to AWK but am a reasonable Perl programmer.
I have actually completed the following task using a perl script, but I feel that AWK *may* be faster so it would be good to know if what I want to do can be carried out in AWK as in all likelihood I will need to repeat the task again and possibly on larger files.
The task is quite simple:
A file contains a list of names. These also exist as column headers in several other files.
So for example:
name_file has:
red
blue
purple
other_file1 has:
green blue yellow red
0.4 0.3 0.2 0.7
0.1 0.5 0.9 0.2
etc...
What I need to do is extract the full column where the header matches a name from the name_file, so in this case it would be:
blue red
0.3 0.7
0.5 0.2
and then send those selected columns to a new file.
I know that you can use something like
to achieve this from the command line, but this isn't rally appropriate for this case.
Is it possible to do all the above with awk? I also toyed with the idea of doing the original matching in perl and then passing a string with all the positions, a bit like this:
But this had all sorts of errors, mainly because it won't accept the string being passed with the -f.
Any pointers gladly accepted!
Firstly apologies, I am completely new to AWK but am a reasonable Perl programmer.
I have actually completed the following task using a perl script, but I feel that AWK *may* be faster so it would be good to know if what I want to do can be carried out in AWK as in all likelihood I will need to repeat the task again and possibly on larger files.
The task is quite simple:
A file contains a list of names. These also exist as column headers in several other files.
So for example:
name_file has:
red
blue
purple
other_file1 has:
green blue yellow red
0.4 0.3 0.2 0.7
0.1 0.5 0.9 0.2
etc...
What I need to do is extract the full column where the header matches a name from the name_file, so in this case it would be:
blue red
0.3 0.7
0.5 0.2
and then send those selected columns to a new file.
I know that you can use something like
Code:
awk -f2,4 other_file1 > new_file1
Is it possible to do all the above with awk? I also toyed with the idea of doing the original matching in perl and then passing a string with all the positions, a bit like this:
Code:
system(awk -f$stringpos $file > $fileout)
Any pointers gladly accepted!