LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   extracting columns with awk (https://www.linuxquestions.org/questions/programming-9/extracting-columns-with-awk-867458/)

gav251 03-09-2011 07:25 AM

extracting columns with awk
 
hi
why does this only use column 3?

awk '{print $3 $6 $7 >> "area.plt" }' mol.are
thnx.
g.

jschiwal 03-09-2011 07:29 AM

How are we supposed to know what .plt and .are files are.

Also, the >> "area.plt" part should be outside the awk command. Otherwise we can't tell you what the output would look like without a sample of the input.

Reuti 03-09-2011 07:39 AM

Quote:

Originally Posted by jschiwal (Post 4284130)
Also, the >> "area.plt" part should be outside the awk command.

According to man awk it's allowed to be used as option to a print command. Mabye it's a gawk extension.

But of course, w/o knowing the input we can't say much.

jschiwal 03-09-2011 07:44 AM

Thanks Reuti. I didn't know that. It does look strange, and I don't see why you would unless you are running an actual awk script.

colucix 03-09-2011 08:14 AM

Quote:

Originally Posted by jschiwal (Post 4284146)
I don't see why you would unless you are running an actual awk script.

Actually it is useful only when you have multiple redirections (to different files) inside the awk script or when the file name is built dinamycally under certain conditions.

@gav251: please follow the advice in the previous posts and show us the content (or just a sample) of the input file. Don't forget to embed it in CODE tags to preserve spacing and tabs (since they might be important to solve the puzzle). To use CODE tags, either put [CODE] and [/CODE] around the text or switch to advanced mode and press the # button.

gav251 03-10-2011 05:52 AM

The .plt file is a new file, > would be ok. .mol file is a large file containing mathematical data about a proteins geometry. I didn't post it since the data is irrelevant. I just need to redirect columns 3, 6 and 7. Sorry for the ambiguity.
g.

Reuti 03-10-2011 06:24 AM

Quote:

Originally Posted by gav251 (Post 4285331)
I didn't post it since the data is irrelevant. I just need to redirect columns 3, 6 and 7.

Obviously it's not irrelevant, otherwise your awk command would work. So showing one line of the input and the result which is produced by this line would allow to investigate the behavior.

colucix 03-10-2011 08:40 AM

Quote:

Originally Posted by Reuti (Post 4285366)
Obviously it's not irrelevant, otherwise your awk command would work. So showing one line of the input and the result which is produced by this line would allow to investigate the behavior.

The same from me. The result from such a simple code should be obvious, so most likely the problem resides in the input format: separators, hidden characters and so on. Please post a line of input, the corresponding output (as suggested above) plus the output of the following:
Code:

head -3 file.mol | od -c
and please use CODE tags.


All times are GMT -5. The time now is 05:04 AM.