If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk print tab delimited new line file; Need help urgently

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-11, 11:19
biobee07 biobee07 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
awk print tab delimited new line file; Need help urgently

I am trying to print out my file in tab delimited formatted along with a new line after end of each line. However I am missing out on the combination I need to put for printing out this format.
Following is my input file: ( this is a space delimited file)
NA18558 NA18609 NA18537 NA18632 NA18564 NA18582 NA18561 NA18611 NA18540 NA18633 NA18566 NA18592 NA18562 NA18612 NA18542NA18635 NA18570 NA18593 NA18563 NA18620 NA18545 NA18636 NA18571 NA18594 NA18572 NA18621 NA18547 NA18637 NA18573 NA18603NA18526 NA18622 NA18550 NA18576 NA18524 NA18605 NA18529 NA18623 NA18552 NA18577 NA18608 NA18532 NA18624 NA18555 NA18579
rs4880608 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 NA 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2

I am planning to print it out as tab delimited file.

Here is my shell script.

#!/bin/sh
awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } }' CHB_NS_SNP.NEW.txt

I am print columns 1 -45 ie. the entire width of the file and want to add a \n in the shell scipt. Only I am not sure how to do it.

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old 03-10-11, 12:08
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Try:
Code:
awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } print; }' CHB_NS_SNP.NEW.txt
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 03-10-11, 12:29
biobee07 biobee07 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
thanks

Quote:
Originally Posted by LKBrwn_DBA View Post
Try:
Code:
awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } print; }' CHB_NS_SNP.NEW.txt
Thanks LKBrwn. IT works!
Reply With Quote
  #4 (permalink)  
Old 03-10-11, 14:52
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Wink

yw........
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 03-13-11, 10:21
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Alternatively:
Code:
sed "s/ /<tab>/g" input.file >output.file
#where <tab> is replaced with the actual tab character
Reply With Quote
  #6 (permalink)  
Old 03-14-11, 05:51
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Alternatively:
Code:
tr ' ' '\t' <input.file >output.file
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On