how extract certain value within a line using awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how extract certain value within a line using awk
# 1  
Old 06-10-2009
how extract certain value within a line using awk

hi if would like to get the phone number as an output, can you guide me here please

<A>213444555</A><B><B>ABCDEFG</B>

I just want to get the phone number from the file in between <A> and </A>

Thanks
# 2  
Old 06-10-2009
what have you tried??
# 3  
Old 06-10-2009
Thanks for the reply

I have tried the following

cat test|awk -F '<' '{print $1}'|grep '[0-9]\{2\}'
cat test|grep '\<"<A>[0-9]</A>"\>'

test file has the value in it
# 4  
Old 06-10-2009
use sed
Code:
sed 's/\(<A>\)\([0-9]*[0-9]\)\(.*\)/\2/g' test

or
Code:
 
sed 's/<A>\([0-9]*[0-9]\)\(.*\)/\1/g' test

# 5  
Old 06-10-2009
Thanks Very much, should it work for Alphebets by changing

0-9 to A-Z?
Thanks again
# 6  
Old 06-10-2009
Quote:
Originally Posted by imran721
Thanks Very much, should it work for Alphebets by changing

0-9 to A-Z?
Thanks again
yes it will but where and what you want to extract depending on that use it
# 7  
Old 06-10-2009
Thanks again Vidya, just one more thing, if you could explain the following part, i will really appereciate it

's/<A>\([0-9]*[0-9]\)\(.*\)/\1/g' and what difference does 2 make instead of one while replaceing it

sed 's/\(<A>\)\([0-9]*[0-9]\)\(.*\)/\2/g'

Thanks Again

-----Post Update-----

hi Again
sorry but this is what I was exactly trying to get from the following output but I thought that piece of code would work but didnt work for the following output

! TICKET NBR : 2 ! GSI : 23 ! 111111111 PPDBEP1 ! 356411158 RI:12 ! 3100.2.22.1 MTC ! 3100.2.20.1 4034673533 ! 3100.2.13.1 0.0
0 ! 3100.2.14.2 1348 ! 1.2.1.8 <A>1001001265856</A><B>ABCMobile</B><C>9999999</C><D>9999</D><E></E><F>CALGARY AB</
F><G>722X _CALGARY AB</G><H>99999</H><I>D212</I><J>09/06/2009 21:37:40</J><Q></Q><R>P1_T1_LOCAL</R><K>RL 0.00/60/60 QL 1380 C


i wanted to get abc mobile by itself form the output please
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to extract and print first occurrence of pattern in each line

I am trying to use awk to extract and print the first ocurrence of NM_ and NP_ with a : before in each line. The input file is tab-delimeted, but the output does not need to be. The below does execute but prints all the lines in the file not just the patterns. Thank you :). file tab-delimeted ... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk to extract tag and add to each line

In the awk below which executes as is, I am trying to add a condition that will extract the text or value after the FR= for the lines in each line of file1 compared to file2. As is the lines between the two files are either a match, Missing in file 1, or Missing in file2, but I can not add the... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

awk to extract digit in line of text and create link

I am trying to extract the number in bold (leading zero removed) after Medexome_xx_numbertoextractin file and create an output using that extracted number. In the output the on thing that will change is the number the other test is static and will be the same each time. Thank you :). file ... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

Extract values in a line using awk

hello all, I need your help in extracting values of some parameter within a line using awk. for example: i have the below line available in a file and i want to extract the values of only CustomerId, s_PackageId and s_HZINumbers in order the result to be as ... (13 Replies)
Discussion started by: nael_najib
13 Replies

5. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

6. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. UNIX for Dummies Questions & Answers

awk, extract last line of multiple files

Hi, I have a directory full of *.txt files. I would like to print the last line of every file to screen. I know you can use FNR for printing the first line of each file, but how do I access the last line of each file? This code doesn't work, it only prints the last line of the last file:BEGIN... (5 Replies)
Discussion started by: Liverpaul09
5 Replies

8. Shell Programming and Scripting

How to extract part of xml line via awk?

Hi, I like to set a variable "name" automatically by reading an xml file. The name should be set to the date, which is a part of the following line of the xml file: <sceneID>C82_N32_A_SM_strip_008_R_2009-11-24T04:22:12.790028Z</sceneID> How can I separate this line, that the name will... (6 Replies)
Discussion started by: friend
6 Replies

9. Shell Programming and Scripting

how to extract part of xml line via awk?

Hi, I like to set a variable "name" automatically by reading an xml file. My code looks like this: set name = `awk '/<generationTime>/,/<\/generationTime>/ p' $xml_name` the "name" is thus set to <generationTime>2004-12-01T08:23:50.000000</generationTime> How can I separate this line,... (3 Replies)
Discussion started by: friend
3 Replies

10. Shell Programming and Scripting

awk: need to extract a line before a pattern

Hello , I need your help to extract a line in a big file , and this line is always 11 lines before a specific pattern . Do you know a way via Awk ? Thanks in advance npn35 (17 Replies)
Discussion started by: npn35
17 Replies
Login or Register to Ask a Question