LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 12-19-2011, 09:11 AM   #1
irwinyeo
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Rep: Reputation: Disabled
extract last few of line data from txt file


hi,

this is my .txt file.

Read RMS voltage Register!
00980C7E
0.5939
Actual voltage!
237.5762
Read RMS current Register!
0002AEE6
0.0104
Actual current!
0.0873
Read status Register!
007FC3BC
Read RMS voltage Register!
009805E8
0.5938
Actual voltage!
237.5360
Read RMS current Register!
0002AF74
0.0104
Actual current!
0.0874
Read status Register!
007FC2D6
Read RMS voltage Register!
0097F7F8
0.5936
Actual voltage!
237.4509 ---------------------------> (i need this value)
Read RMS current Register!
0002ACE0
0.0104
Actual current!
0.0870 ------------------------> (i need this value)
Read status Register!
00920089



how do i write a c++ program to get the values?

as this text file kept updating, i need to always get the newest value (which values are insert at the bottom) will it affect the updating of the text file?

sry noob here...

Last edited by irwinyeo; 12-19-2011 at 07:21 PM.
 
Old 12-19-2011, 10:23 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
What do you mean by "extract the last few lines"? Simply get the last <n> lines? Or do you want to parse them to get the data?

Also, it it really necessary to do this in C++ (that is, this is part of a larger C++ program)? Or can it also be done using shell scripting, which would probably be simpler?
 
Old 12-19-2011, 07:21 PM   #3
irwinyeo
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
the latest values are at the bottom of the text file so i need the values. i only needed 2 values, the line after "Actual voltage!" and "Actual current!".

ya this is part of a large program, so i need to use c++.
 
Old 12-19-2011, 10:03 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The tail command does exactly what your requirements specify. If you need to do this with your own code, it shouldn't be too hard to see how tail does it. I'm pretty sure tail is part of the binutils package, if you want to track down the sources.
--- rod.
 
Old 12-20-2011, 02:56 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by theNbomr View Post
I'm pretty sure tail is part of the binutils package, if you want to track down the sources.
You mean Coreutils.

Last edited by Nylex; 12-20-2011 at 09:46 AM.
 
Old 12-20-2011, 09:07 AM   #6
irwinyeo
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
any links i can read up on coreutils?
 
Old 12-20-2011, 09:47 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
The Coreutils homepage (which could have easily been found using a search engine) will give you access to the documentation and sources.
 
Old 12-20-2011, 09:47 AM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, coreutils is the correct package; thanks to Nylex for the correction. The definitive link for info would be the GNU coreutils website, or more specifically, the page for the tail utility.

--- rod.
 
  


Reply



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
C - how to open a txt file and then display the data UltimateDesi Programming 20 10-17-2010 10:32 AM
Script for pulling data out of a txt file schapman43 Linux - Newbie 7 08-03-2010 01:07 PM
Using nslookup from data in a .txt file in BackTrack RexRogan Linux - Newbie 1 12-08-2009 02:35 AM
how to remove a line from a txt file graziano1968 Linux - General 16 11-07-2009 05:17 PM
Read a line in a txt file with bash orgazmo Programming 5 05-03-2005 07:10 AM

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

All times are GMT -5. The time now is 07:25 AM.

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