awk for string between > and /n


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk for string between > and /n
# 1  
Old 03-18-2015
awk for string between > and /n

Hi, I have a file that looks something like the following:

Code:
>IGHV4-4*02
caggtgcagctgcaggagtcgggcccaggactggtgaagccttcggggaccctgtcc
ctcacctgcgctgtctctggtggctccatcagcagtagtaactggtggagt
tgggtccgccagcccccagggaaggggctggagtggattggggaaatctatcatagt
gggagcaccaactacaacccgtccctcaagagtcgagtcaccatatcagta
gacaagtccaagaaccagttctccctgaagctgagctctgtgaccgccgcggacacggcc
gtgtattactgtgcgagaga
>IGHV4-4*03
caggtgcagctgcaggagtcgggcccaggactggtgaagcctccggggaccctgtcc
ctcacctgcgctgtctctggtggctccatcagcagtagtaactggtggagt
tgggtccgccagcccccagggaaggggctggagtggattggggaaatctatcatagt
gggagcaccaactacaacccgtccctcaagagtcgagtcaccatatcagta
gacaagtccaagaaccagttctccctgaagctgagctctgtgaccgccgcggacacggcc
gtgtattactg
>IGHV4-4*04
caggtgcagctgcaggagtcgggcccaggactggtgaagcctccggggaccctgtcc
ctcacctgcgctatctctggtggctccatcagcagtagtaactggtggagt
tgggtccgccagcccccagggaaggggctggagtggattggggaaatctatcatagt
gggagcaccaactacaacccgtccctcaagagtcgagtcaccatatcagta
gacaagtccaagaaccagttctccctgaagctgagctctgtgaccgccgcggacacggcc
gtgtattactg

I would like to use awk to obtain a list [IGHV4-4*02, IGHV4-4*03, IGHV4-4*04]. How do I awk for the string between > and the newline?
# 2  
Old 03-19-2015
Try:
Code:
sed -n 's/^>//p' file

# 3  
Old 03-19-2015
Hello jyu429,

Following may also help you in same.
Code:
awk '/^>/ {print substr($0,2)}'  Input_file

Output will be as follows.
Code:
IGHV4-4*02
IGHV4-4*03
IGHV4-4*04

Thanks,
R. Singh
# 4  
Old 03-19-2015
This question is pretty similar to the other four requests you have made to have us write code for you. When you ask for help in the future, please show us what you have tried to solve your problem.

Try something like:
Code:
awk -F'>' 'NF > 1 {printf("%s%s", cnt++ ? ", " : "[", $2)} END {print "]"}' file

which, with your sample input, produces the output:
Code:
[IGHV4-4*02, IGHV4-4*03, IGHV4-4*04]

which seems to match the output you wanted.

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

3. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

4. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

5. Shell Programming and Scripting

awk string comparison unterminated quoted string andrule of thumb

I have the logic below to look up for matches within the columns between the two files with awk. In the if statement is where the string comparison is attempted with == The issue seems to be with the operands, as 1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies

6. Shell Programming and Scripting

awk : match the string and string with the quotes :

Hi all, Here is the data file: - want to match only lan3 in the output . - not lan3:1 file : OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE=""... (2 Replies)
Discussion started by: rveri
2 Replies

7. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

8. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

9. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

10. Shell Programming and Scripting

awk a string

Hi #!/usr/bin/bash ITEM=apple cat file1.tsv | awk -F "\t" '($3 == $ITEM) {print $2}' awk: illegal field $(), name "ITEM" input record number 1, file source line number 1 Here is file1.tsv type category_id item code remarks fruits 1 apple 345 567 fruits 3 banana 44 555 ... (8 Replies)
Discussion started by: ./hari.sh
8 Replies
Login or Register to Ask a Question