LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script for pulling data out of a txt file (https://www.linuxquestions.org/questions/linux-newbie-8/script-for-pulling-data-out-of-a-txt-file-823824/)

schapman43 08-03-2010 09:00 AM

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,

druuna 08-03-2010 09:08 AM

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.

lartman 08-03-2010 09:21 AM

tail -n 1 > somewhere

schapman43 08-03-2010 11:30 AM

Quote:

Originally Posted by druuna (Post 4054013)
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!

druuna 08-03-2010 11:30 AM

You're welcome :)

schapman43 08-03-2010 11:36 AM

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

druuna 08-03-2010 11:39 AM

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?).

schapman43 08-03-2010 01:07 PM

Quote:

Originally Posted by druuna (Post 4054271)
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


All times are GMT -5. The time now is 09:27 PM.