LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2011, 07:25 AM   #1
gav251
LQ Newbie
 
Registered: Feb 2010
Posts: 18

Rep: Reputation: 0
Unhappy extracting columns with awk


hi
why does this only use column 3?

awk '{print $3 $6 $7 >> "area.plt" }' mol.are
thnx.
g.
 
Old 03-09-2011, 07:29 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 03-09-2011, 07:39 AM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by jschiwal View Post
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.
 
Old 03-09-2011, 07:44 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 03-09-2011, 08:14 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by jschiwal View Post
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.
 
Old 03-10-2011, 05:52 AM   #6
gav251
LQ Newbie
 
Registered: Feb 2010
Posts: 18

Original Poster
Rep: Reputation: 0
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.
 
Old 03-10-2011, 06:24 AM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by gav251 View Post
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.
 
Old 03-10-2011, 08:40 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Reuti View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting columns from multiple files with awk orcaja Linux - Newbie 7 02-14-2012 10:24 PM
[SOLVED] Extracting columns ben1173 Linux - General 5 10-18-2010 10:37 PM
AWK - combining multiple columns AlexYZ Programming 5 02-24-2010 07:09 AM
printing multiple columns with awk kdelover Programming 16 12-16-2009 09:10 AM
Using awk to switch columns bioinformatics_guy Linux - Newbie 3 10-30-2008 09:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration