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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed or awk, cut, to extract specific data from line
# 1  
Old 11-01-2012
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,
# 2  
Old 11-01-2012
May be like this:
Code:
awk -F/ '/Total Handled/{print $2+0}' file

# 3  
Old 11-01-2012
hmm, that one it is just returning 0.
# 4  
Old 11-01-2012
elixir_sinari's solution should work.

You can also try using:

Code:
awk '/Total Handled/ { for(i=0;i<NF;i++) if($i=="/") print $(i+1); } ' infile

# 5  
Old 11-01-2012
Thanks guys, this last one works like a charm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

2. Shell Programming and Scripting

sed / awk to get specific word in line

I have http log that I want to get words after specific "tag", this a sample line from the log: 98,POST,200 OK,www.facebook.com,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,/ajax/updatestatus.php?__a=1,datr=P_H1TgjTczCHxiGwdIF5tvpC; lu=Si1fMkcrU2SInpY8tk_7tAnw;... (6 Replies)
Discussion started by: erlanq
6 Replies

3. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

4. Shell Programming and Scripting

Router ping log extract data from it Awk/Sed/grep

Hi, I am new to this world.. Using expect i loging to router and checking ping response to my links. I need to genarate report using this output and that report contains only three file link name, packet loss, latency. my output of script is like below: -bash-3.00$ monmw/mwbkp... (2 Replies)
Discussion started by: jkmistry
2 Replies

5. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

6. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

7. UNIX for Advanced & Expert Users

bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this: clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6... (3 Replies)
Discussion started by: Pioneer1976
3 Replies

8. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

9. Shell Programming and Scripting

sed or awk to extract data from Xml file

Hi, I want to get data from Xml file by using sed or awk command. I want to get the following result : mon titre 1;Createur1;Dossier1 mon titre 1;Createur1;Dossier1 and save it in cvs file (fichier.cvs). FROM this Xml file (test.xml): <playlist version="1"> <trackList> <track>... (1 Reply)
Discussion started by: yeclota
1 Replies

10. Shell Programming and Scripting

Can't figure out how to display specific data from a line using awk.

Hello, I cannot figure this one out. I would like to do the following. I have a line that has 7 words. It is possible that the line can have 20 words too. I always want to show the 9th word and beyond. The 9th word will always change so I do not have something to search for, so I think... (1 Reply)
Discussion started by: ctcuser
1 Replies
Login or Register to Ask a Question