niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Can perl be used to prepend to a file?
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Stachu 'Dozzie' K.
*nix forums Guru Wannabe


Joined: 30 Mar 2005
Posts: 250

PostPosted: Mon Feb 07, 2005 1:32 am    Post subject: Re: Can perl be used to prepend to a file? Reply with quote

On 2005-02-07, dave@geol.ucsb.eduWWW wrote:
Quote:
I often use:

perl -pi -e 's/old-re/new-re/' $file

but could it be used similarly to prepend a line to a textfile?
so that e.g. a file about to be generated with:

lynx -dump -nolist http://myURL |cut -c3- > mytextfile

gets the URL prepended to mytextfile?

You mean [ "`head -n 1 mytextfile`" = 'http://myURL' ] ?
lynx -dump -nolist http://myURL | perl -pe '$_ = "http://myURL\n$_" if 1 .. 1' | cut -c3- > mytextfile
Of course cut is redundant here while playing Perl:
lynx -dump -nolist http://myURL | perl -pe '$_ = substr $_, 2; $_ = "http://myURL\n$_" if 1 .. 1' > mytextfile
Probably you would like Perl to get automatically URL, but I'm leaving
it for you as a kind of homework.

--
Stanislaw Klekot
Back to top
dave@geol.ucsb.eduWWW
*nix forums beginner


Joined: 07 Feb 2005
Posts: 2

PostPosted: Mon Feb 07, 2005 1:20 am    Post subject: Re: Can perl be used to prepend to a file? Reply with quote

I just realized that it don't need perl and solved it simply with:

URL=http://myURL
(echo $URL; echo ""; lynx -dump -nolist $URL |cut -c3- ) > mytextfile

Quoting myself in a previous post:
Quote:
I often use:

perl -pi -e 's/old-re/new-re/' $file

but could it be used similarly to prepend a line to a textfile?
so that e.g. a file about to be generated with:

lynx -dump -nolist http://myURL |cut -c3- > mytextfile

gets the URL prepended to mytextfile?

Thanks.

Dave
Back to top
dave@geol.ucsb.eduWWW
*nix forums beginner


Joined: 07 Feb 2005
Posts: 2

PostPosted: Mon Feb 07, 2005 1:03 am    Post subject: Can perl be used to prepend to a file? Reply with quote

I often use:

perl -pi -e 's/old-re/new-re/' $file

but could it be used similarly to prepend a line to a textfile?
so that e.g. a file about to be generated with:

lynx -dump -nolist http://myURL |cut -c3- > mytextfile

gets the URL prepended to mytextfile?

Thanks.

Dave
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 11:18 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Need Help with Program in Perl on a Netware Server fhadzocos@gmail.com Perl 3 Fri Jul 21, 2006 1:57 pm
No new posts Running php file everyday on scheduled time sachin PHP 1 Fri Jul 21, 2006 12:49 pm
No new posts Regarding thesaurus iso file Srikanth modules 0 Fri Jul 21, 2006 10:42 am
No new posts problems using oddmuse with mod_perl2 inside apache2.2 pe... Fergus McMenemie Perl 0 Fri Jul 21, 2006 9:48 am
No new posts Problem with Win32-SerialPort over bluetooth @ windows + ... ctloh Perl 0 Fri Jul 21, 2006 8:08 am

Internet Advertising | Online Advertising | Loan | Repair Bad Credit | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2613s ][ Queries: 20 (0.1709s) ][ GZIP on - Debug on ]