Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-03-2010, 09:00 AM
|
#1
|
LQ Newbie
Registered: May 2005
Posts: 24
Rep:
|
Script for pulling data out of a txt file
I would like to write a script that pulls the last line of data out of a txt file and then saves it to another txt file. The txt file that I am looking at resides here.
http://www.swpc.noaa.gov/ftpdir/list...ulder_iono.txt
I know I can grab that file using wget. I've done a little scripting but nothing major. Can someone push me in the right direction?
Thanks,
|
|
|
08-03-2010, 09:08 AM
|
#2
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
This will grep the last line of the mentioned file and saves it in foo.txt:
wget -qO - http://www.swpc.noaa.gov/ftpdir/list...ulder_iono.txt | tail -1 > foo.txt
Hope this helps.
|
|
1 members found this post helpful.
|
08-03-2010, 09:21 AM
|
#3
|
LQ Newbie
Registered: Jan 2004
Location: Sydney, Australia
Distribution: RHEL
Posts: 22
Rep:
|
tail -n 1 > somewhere
|
|
|
08-03-2010, 11:30 AM
|
#4
|
LQ Newbie
Registered: May 2005
Posts: 24
Original Poster
Rep:
|
Quote:
Originally Posted by druuna
|
foo'king awesome! Thank you guys!
|
|
|
08-03-2010, 11:30 AM
|
#5
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
You're welcome 
|
|
|
08-03-2010, 11:36 AM
|
#6
|
LQ Newbie
Registered: May 2005
Posts: 24
Original Poster
Rep:
|
Is there a way to grab a specific line number? Say if I also wanted to grab the following out of the text.
# YR MO DA HHMM foF2 hmF2 MUF(D) D h'F yF2 fMUF h' fxI foF1 foE hmE foEs fbEs ITEC
|
|
|
08-03-2010, 11:39 AM
|
#7
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
It is probably not clear to me what is is you want.
You want something like this as output ("header" and the last line)?:
# YR MO DA HHMM foF2 hmF2 MUF(D) D h'F yF2 fMUF h' fxI foF1 foE hmE foEs fbEs ITEC
2010 08 03 1600 5.7 305 3.24 3000 305 86 5.3 325 6.4 4.6 3.2 105 3.7 -1.0 10.0
If that is the case:
wget -qO - http://www.swpc.noaa.gov/ftpdir/list...ulder_iono.txt | sed -ne '/# YR MO DA HHMM/p' -e '$p' > foo.txt
If not please elaborate (with an example?).
Last edited by anon237; 08-03-2010 at 12:13 PM.
Reason: Added possible command.
|
|
|
08-03-2010, 01:07 PM
|
#8
|
LQ Newbie
Registered: May 2005
Posts: 24
Original Poster
Rep:
|
Quote:
Originally Posted by druuna
Hi,
It is probably not clear to me what is is you want.
You want something like this as output ("header" and the last line)?:
# YR MO DA HHMM foF2 hmF2 MUF(D) D h'F yF2 fMUF h' fxI foF1 foE hmE foEs fbEs ITEC
2010 08 03 1600 5.7 305 3.24 3000 305 86 5.3 325 6.4 4.6 3.2 105 3.7 -1.0 10.0
If that is the case:
wget -qO - http://www.swpc.noaa.gov/ftpdir/list...ulder_iono.txt | sed -ne '/# YR MO DA HHMM/p' -e '$p' > foo.txt
If not please elaborate (with an example?).
|
That is what I was looking for.
I am unable to get it to work though. Foo.txt outputs
2010 08 03 1730 5.7 295 3.12 3000 190 90 4.6 270 6.3 4.6 3.4 100 3.6 -1.0 11.2
Last edited by schapman43; 08-03-2010 at 01:17 PM.
|
|
|
All times are GMT -5. The time now is 03:19 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|