extract string from varying delimiter line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract string from varying delimiter line
# 1  
Old 08-10-2009
extract string from varying delimiter line

Hi

I have lines like this

a=1, b=2, c=3,
a=1, d=4, e=5, b=225,

I need to extract the b=nnn... value. I dont know how many other entries will be before and after it in each line. Ive tried a basic line like
awk '/b=/, $NF ~ /,/ ' myfile.txt
but I think that it doesnt care which comma it picks.

I to begin the selection with b= and end it with the NEXT comma after b=

Any ideas?
Thanks.
# 2  
Old 08-10-2009
please post ur desired output...
# 3  
Old 08-10-2009
desired output would be
b=2
b=225
# 4  
Old 08-10-2009
didnt test it but try...

Code:
awk -F, '{for(i=1;i<NF;i++){if($i ~ /b=[0-9]*/) print $i}}' inputfile

# 5  
Old 08-10-2009
Fantastic. Dedicate that brain to science upon your demise, may it be far into the future. ! Smilie . It worked like a dream
# 6  
Old 08-11-2009
Code:
grep -o "b\([=0-9]\)\+" inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract a portion of string from each line in Linux

Hi I have to extract the destination path information from each record the file is of variable length so I will not be able to use the print command.The search should start on variable "destinationPath" and it should end at immediate "," also the first field has to be printed Input File:... (7 Replies)
Discussion started by: rkakitapalli
7 Replies

2. Shell Programming and Scripting

How to extract work in line string.?

Hello all, Soon I will be receiving a new file. I've asked the source system to put "TRAILER.1+0000007+1" for the trailer to indicate full receipt of file. I need to know how to separate TRAILER so I can use it in a if statement. I used the tail command but not sure how to incorporate awk or... (11 Replies)
Discussion started by: pone2332
11 Replies

3. Shell Programming and Scripting

Extract string between two delimiter

I want a string between two delimeter like ( ) from file. Input File, 2007_08_07_IA-0100-014_(January).PDF 2007_08_07_IA-0100-031_(January February March April June July).PDF 2008-02-28_KR-1022-003_(January febuary march april may).CSV Output File, January January February... (19 Replies)
Discussion started by: Pratik Majithia
19 Replies

4. Shell Programming and Scripting

How to extract text from STRING to end of line?

Hi I have a very large data file with several hundred columns and millions of lines. The important data is in the last set of columns with variable numbers of tab delimited fields in front of it on each line. Im currently trying sed to get the data out - I want anything beetween :RES and... (4 Replies)
Discussion started by: Manchesterpaul
4 Replies

5. Shell Programming and Scripting

Extract a string from a line

Hiee all Can anyone tell me how to extract a string from a given line. STAPISDK_RELEASE_32_BL012_2011_JAN_25.1597 I want to extract BL012 from above. as 102 keeps on changing i want smthing like that it extract BL and 102 extrct by its own. Thankx guyzz (9 Replies)
Discussion started by: abhijtr
9 Replies

6. Shell Programming and Scripting

search for a string without fixed delimiter in the line

Hi Need your help to assign the string to a variable from a line which has no fixed delimter in unix. for example , my file contains Name="report"" File Name one="test1" File Name two="test2" now how do I read report , test1 and test2 ? var1=report var2=test1 var3=test2 ... (1 Reply)
Discussion started by: rashmisb
1 Replies

7. Shell Programming and Scripting

Perl REGEX - How do extract a string in a line?

Hi Guys, In the following line: cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br I need to extract this string: portal.090710.191533.428571000 As you can see this string always will be bettween "cn=" and "," strings. Someone know one regular expression to... (4 Replies)
Discussion started by: maverick-ski
4 Replies

8. Shell Programming and Scripting

How to extract a string from a file ignoring new line

Hi, sumdays before i had posted a query with same subject. i got sum great help from great ppl which solved my problem then. But now there is a small problem with the code that i need the experts help upon. for parsing a text like this where $ had been the delimiter between... (3 Replies)
Discussion started by: suresh_kb211
3 Replies

9. Shell Programming and Scripting

how to extract a string value from the given line

Hi I have an input as follows: param1:value1|param2:value2|param3:value3|param4:value4|param5:value5 where, "|" and ":" are delimiters Now suppose, I want to extract the value corresponding to "param4", i.e. "value4" in this case. In case we use awk, I want to use the value in shell... (1 Reply)
Discussion started by: gaurav_1711
1 Replies

10. Shell Programming and Scripting

Append tabs at the end of each line in NAWK -- varying fields

Hi, I need some help in knowing how I can append tabs at the end of each line... The data looks something like this: field1, field2, field3, field4 1 2 3 4 5 I have values in field1 and field 2 in the first row and I would like to append tab on field3 and field4 for the first row..and in... (6 Replies)
Discussion started by: madhunk
6 Replies
Login or Register to Ask a Question