Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Practical question!!! 1

Status
Not open for further replies.

demis001

Programmer
Aug 18, 2008
94
US
I want give each line a unique id. Here is the
inpute data:

TGAGGTATTATGTTCGAT 1
GGGGGCGACTCTGGGATG 3
CGGAGCGGGCTTCTCTTC 1
AGGGGGATGGTGGAAAAA 1
TGGCTCAGGGCAGAAGGA 2
TACTACAGGGTAGAACC 49

I want to give each line an id looks like this
>xxx_1_x1 TGAGGTATTATGTTCGAT
>xxx_2_x3 GGGGGCGACTCTGGGATG
>xxx_3_x1 CGGAGCGGGCTTCTCTTC
Then I want to covert to fasta file
using awk '{print $1; print $2}' the above output file

If you incorprate the above script line:

The final file I need is this
>xxx_1_x1
TGAGGTATTATGTTCGAT
>xxx_2_x3
GGGGGCGACTCTGGGATG

Dereje
 
I have no clue even How to start!

Dereje

I usally do in excel + perl and wondering if I can make my life easy with awk. I start awk a week ago. Itration is required to enter the header id.

Thank you brother
 
Try this. NR is a special variable containing the record number.

Code:
awk '{ print ">xxx_" NR "_x" $2; print $1 }' inputfile > outputfile

Annihilannic.
 
Many thanks,

If I new NR variable before I can write that line. Thank you for introducing me to awk. You know, it takes me more than 30 min to create the same file. Now 50 second!

Thank you and love awk

Dereje
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top