How to fetch a value from a single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch a value from a single line
# 1  
Old 01-27-2009
How to fetch a value from a single line

i have the following line:

</PRE></TD></TR><TR><TD><B>Events in</B></TD><TD>95</TD></TR><TR><TD><B>Events/sec</B></TD><TD>0</TD></TR><TR><TD><B>Messages out</B></TD><TD>95</TD></TR><TR><TD><B>Messages/sec


i want get the value of Messages out which has value 95 exists in same row.

can any one please help me on this?
# 2  
Old 01-27-2009
Try replacing all <tokens> with spaces and then passing through awk:
Code:
sed 's/\(<[^>]*>\)/ /g;'

Now you will get:
Code:
      Events in   95     Events/sec   0     Messages out   95     Messages/sec

With a little change, you can change the </TRs> into newlines, making it even easier for awk:
Code:
 sed 's/\(<\/TR>\)/\n/g; s/\(<[^>]*>\)/ /g;'

Now you get:
Code:
  Events in   95
  Events/sec   0
  Messages out   95
  Messages/sec

Now you can pipe through awk:
Code:
<above sed command> | awk '/Messages out/ { print $NF }'

will always print the last field on a line matching "Messages out".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch the values based on a Key using awk from single file

Hi, Please help to fetch the values for a key from below data format in linux. Sample Input Data Format 11055005|PurchaseCondition|GiftQuantity|1 11055005|PurchaseCondition|MinimumPurchase|400 11055005|GiftCatalogEntryIdentifier|Id|207328014 11429510|PurchaseCondition|GiftQuantity|1... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

2. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

3. Shell Programming and Scripting

How to fetch values from a line in a file to variables in UNIX?

Hi, I need to assign values from a lines in a file into variables in unix, i am using Korn shell. I tried the below script from posts but i am unable to fetch every value in a variable. #! /usr/bin/ksh #for file in test.txt; do IFS=$'\|' I=1 while read -a val do echo... (15 Replies)
Discussion started by: karthikram
15 Replies

4. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

6. UNIX for Advanced & Expert Users

how to fetch part of a line and display

Input of data: Student: Hari Roll No: 24777 Phone No: 122334 Student: Sudha Roll No: 247911 Phone No: 34552111 Student: Lata Roll No: 247790 Phone No: 7675656554 Student: Kutty Roll No: 24677 Phone No: 12442334 Student: Sudhar Roll No: 247411 Phone No: 3455244111 ... (4 Replies)
Discussion started by: rampriya.s
4 Replies

7. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

8. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

9. Shell Programming and Scripting

How to fetch a specific line from file

Hi, I have text file in the following strucher . The files contain hondreds of lines. value1;value2;value3;value4 I would like to get back the line with lowest date (values4 field). In this case its line number 3. groupa;Listener;1;20110120162018 groupb;Database;0;20110201122641... (4 Replies)
Discussion started by: yoavbe
4 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question