Awk
Hi all,
I have a question about awk. I need to put a field in a file to another field in another line. for example let us say that file1 contain the following: A B C and file 2 : E F G I want to take field number 2 "$2" from file1 which is (B) to put it as field number 4 "$4" in file 2. How can i do that. Regards, |
If you want to do this from command line, without a more complex GAWK script, you can use a for loop to extract $2 from each line of file1 and append the value at the end of the corresponding line in file2, as in
Code:
count=0 |
So is there is another way to do that without awk?
|
Actually I was thinking about an awk script to send output to an external file, anyway here is a one line command which do the same thing
Code:
gawk '{print $2}' file1 | paste -d \ file2 - |
Thanks for the new command but we still didn't detremine the field in the second file. any idea?
|
Do you mean to insert a column from file1 as any column in file2? Assuming that the two files have the same number of columns and there are no blank elements, you can try something like
Code:
{ getline line < ifile Code:
gawk -v icol=2 -v ocol=2 -v ifile=file1 -f script.awk file2 |
All times are GMT -5. The time now is 03:10 AM. |