| Author |
Message |
Stachu 'Dozzie' K. *nix forums Guru Wannabe
Joined: 30 Mar 2005
Posts: 250
|
Posted: Mon Feb 07, 2005 1:32 am Post subject:
Re: Can perl be used to prepend to a file?
|
|
|
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
|
Posted: Mon Feb 07, 2005 1:20 am Post subject:
Re: Can perl be used to prepend to a file?
|
|
|
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
|
Posted: Mon Feb 07, 2005 1:03 am Post subject:
Can perl be used to prepend to a file?
|
|
|
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 |
|
 |
|