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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format file 1

Status
Not open for further replies.

demis001

Programmer
Joined
Aug 18, 2008
Messages
94
Location
US
Would you please help me in formating the folling file.
File looks like the folloing. I want to capture, The "AC" and ID row and print $2 and $3 if the file contain "hsa_" in column three. See the result file I want at the end of this file.
-----------data----------------
AC MIPF0000001
ID mir-17
MI MI0000071 hsa-mir-17
MI MI0000072 hsa-mir-18a
MI MI0000076 hsa-mir-20a
MI MI0000095 hsa-mir-93
MI MI0000113 hsa-mir-106a
MI MI0008173 cfa-mir-106a
MI MI0008214 ssc-mir-17
MI MI0008562 ptr-mir-18b
MI MI0008579 ptr-mir-20b
//
AC MIPF0000002
ID let-7
MI MI0000001 cel-let-7
MI MI0000060 hsa-let-7a-1
MI MI0000061 hsa-let-7a-2
MI MI0000062 hsa-let-7a-3
MI MI0000063 hsa-let-7b
MI MI0000064 hsa-let-7c
MI MI0000065 hsa-let-7d
MI MI0000066 hsa-let-7e
MI MI0000067 hsa-let-7f-1
MI MI0000068 hsa-let-7f-2
MI MI0000100 hsa-mir-98
MI MI0000137 mmu-let-7g
MI MI0000138 mmu-let-7i
//


-----------Result------------

AC ID Acc Name
MIPF0000001 mir-17 MI0000071 hsa-mir-17
MIPF0000001 mir-17 MI0000072 hsa-mir-18a
MIPF0000001 mir-17 MI0000076 hsa-mir-20a
MIPF0000001 mir-17 MI0000113 hsa-mir-106a
MIPF0000002 let-7 MI0000060 hsa-let-7a-1
MIPF0000002 let-7 MI0000061 hsa-let-7a-2
.....

Thanks as always
 
A starting point (typed, untested):
Code:
awk '
BEGIN{print "AC\tID\tAcc\tName"}
$1=="AC"{AC=$2;next}
$1=="ID"{ID=$2;next}
$3~/^hsa-/{print AC,ID,$2,$3}
' data > result

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top