LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2011, 06:23 AM   #1
Tauro
LQ Newbie
 
Registered: Apr 2011
Posts: 24

Rep: Reputation: 1
Adding a column with awk


Input file
Code:
Ribosomal_L14
PF00238.13
C9JD32_HUMAN/23-91
B9ZVP7_HUMAN/19-80
Q9BTQ7_HUMAN/13-134


Ribosomal_L16
PF00252.12
B8A6G2_HUMAN/1-103
C9J7T6_HUMAN/1-116
Q5HY50_HUMAN/20-183
A6QRI9_HUMAN/5-136
D3DWW6_HUMAN/5-167

Ribosomal_L17
PF01196.13
D3DQU3_HUMAN/28-126
Desired output:
Code:
Ribosomal_L14 PF00238.13 C9JD32_HUMAN/23-91
Ribosomal_L14 PF00238.13 B9ZVP7_HUMAN/19-80
Ribosomal_L14 PF00238.13 Q9BTQ7_HUMAN/13-134

Ribosomal_L16 PF00252.12 B8A6G2_HUMAN/1-103
Ribosomal_L16 PF00252.12 C9J7T6_HUMAN/1-116
Ribosomal_L16 PF00252.12 Q5HY50_HUMAN/20-183
Ribosomal_L16 PF00252.12 A6QRI9_HUMAN/5-136
Ribosomal_L16 PF00252.12 D3DWW6_HUMAN/5-167

PLz help me out with awk.!!
 
Old 07-27-2011, 07:17 AM   #2
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Code:
awk '{
  for ( i = 2; ++i <= NF; )
    print $1, $2, $i
  print x	
  }' RS= infile
 
Old 07-27-2011, 07:41 AM   #3
Tauro
LQ Newbie
 
Registered: Apr 2011
Posts: 24

Original Poster
Rep: Reputation: 1
Thanks for the code. What i get with this is:
Code:
1-cysPrx_C PF10417.3 PRDX3_HUMAN
1-cysPrx_C PF10417.3 218-253
1-cysPrx_C PF10417.3 D3DRC9_HUMAN
1-cysPrx_C PF10417.3 218-253
1-cysPrx_C PF10417.3 Q53HC2_HUMAN
1-cysPrx_C PF10417.3 218-253
1-cysPrx_C PF10417.3 Q14579_HUMAN
1-cysPrx_C PF10417.3 1-27

..
..
Well I sorted out this problem of printing every field with $1 and $2. Putting a field separator solved it.
Thanks again for the help
 
1 members found this post helpful.
  


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
[SOLVED] Not able to extract last column from awk vinaytp Linux - Newbie 4 05-20-2011 04:27 AM
awk multiple column into single column ilukacevic Programming 49 07-19-2010 07:23 PM
Column statistic by awk ? cs24 Programming 7 01-15-2010 05:41 AM
Change column value with AWK RyudoBlaze Programming 2 04-25-2009 03:05 AM
awk column printing schneidz Programming 7 09-29-2005 06:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:51 PM.

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