LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 08-03-2010, 09:00 AM   #1
schapman43
LQ Newbie
 
Registered: May 2005
Posts: 24

Rep: Reputation: 15
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,
 
Old 08-03-2010, 09:08 AM   #2
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
Old 08-03-2010, 09:21 AM   #3
lartman
LQ Newbie
 
Registered: Jan 2004
Location: Sydney, Australia
Distribution: RHEL
Posts: 22

Rep: Reputation: 17
tail -n 1 > somewhere
 
Old 08-03-2010, 11:30 AM   #4
schapman43
LQ Newbie
 
Registered: May 2005
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by druuna View Post
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.
foo'king awesome! Thank you guys!
 
Old 08-03-2010, 11:30 AM   #5
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
Old 08-03-2010, 11:36 AM   #6
schapman43
LQ Newbie
 
Registered: May 2005
Posts: 24

Original Poster
Rep: Reputation: 15
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
 
Old 08-03-2010, 11:39 AM   #7
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 08-03-2010, 01:07 PM   #8
schapman43
LQ Newbie
 
Registered: May 2005
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by druuna View Post
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.
 
  


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
How can I use Shell script to edit a data at a particular location in a txt file? leena_d Programming 30 02-08-2010 12:43 AM
Using nslookup from data in a .txt file in BackTrack RexRogan Linux - Newbie 1 12-08-2009 02:35 AM
Problem with shell script - pulling two fields from a file Dcrusoe Programming 6 05-15-2009 02:58 PM
How to read HTML or TXT file and output the data? koolkicks311 Programming 1 04-20-2007 11:13 PM
SH SCRIPT +pulling information from a text file chrisfirestar Linux - General 1 01-30-2004 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:19 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