LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2011, 11:42 AM   #1
D4rKn3sSyS
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
How to take a int from 2 lines of text


Hey mates, when I do a logcat, i got lot of lines, that I filter with a grep, at end, I just got some lines like this:

Code:
I/ActivityManager( 1763): Config changed: { scale=1.0 imsi=732/123 loc=es_ES touch=3 keys=2/1/2 nav=2/1 orien=1 layout=17 uiMode=17 seq=15}

I/ActivityManager( 1763): Config changed: { scale=1.0 imsi=732/123 loc=es_ES touch=3 keys=2/1/2 nav=2/1 orien=1 layout=17 uiMode=17 seq=17}
but I only need the 17 that is after seq=, ignoring the 15 from the first code, and store it as a Int, so how can i do it?
PD: This is for android device, but problem is with programming not with SO

Last edited by D4rKn3sSyS; 04-20-2011 at 01:00 PM.
 
Old 04-20-2011, 11:56 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well I guess the question to you would be how do we know to ignore the 15? I assume it may not always be 15 nor the other line always 17.

Or maybe the case is you always want the entry from the last line?

Until you are a little more clear it is difficult to assist.
 
Old 04-20-2011, 11:58 AM   #3
D4rKn3sSyS
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
I got lot of lines like that, lets assume 10, i wanna ignore the first 9, and only take the int from the last line, and yes, they will be not allways 15 and 17, maybe 1 and 3 or something like that

Last edited by D4rKn3sSyS; 04-20-2011 at 12:08 PM.
 
Old 04-20-2011, 12:40 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,218

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Code:
tail -n 1 log.txt | cut -d " " -f 15 | cut -d "=" -f 2 | cut -d "}" -f 1
Or

Code:
tail -n 1 log.txt | cut -d "q" -f 2 | sed 's/=\([0-9]*\)}/\1/'
I'm sure there's a simpler expression, but both of these work, and you get the idea.

Last edited by dugan; 04-20-2011 at 12:50 PM.
 
1 members found this post helpful.
Old 04-20-2011, 01:00 PM   #5
D4rKn3sSyS
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Shit man i love you (no homo) thanks its working now
 
Old 04-21-2011, 06:09 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Sometimes I use tac in certain situation to read the last entry (i.e. first entry from the file in reverse order) and exit from any script after a match.
 
Old 04-21-2011, 10:06 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Code:
awk -F"[={}]" 'END{print $(NF-1)}' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash text to variable accessing individual text lines patolfo Programming 11 05-11-2010 10:21 AM
Remove lines in a text file based on another text file asiandude Programming 10 01-29-2009 10:59 AM
Adding lines of text to beginning of a text file BillKat Programming 2 01-19-2009 10:40 AM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
Networking&Text files; A string or two, and LOTS of int's quentusrex Programming 9 10-27-2004 05:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration