Use perl from the command line as shown below.
|
anonymous from United Kingdom
|
|
|
|
Hi
I tried using the above command and all i get is K:\test>perl -pi -e 's/searchterm/replaceterm/' *.html
Can't open *.html: Invalid argument.
can you help
Thanks
ak
ajay.jindle@gmail.com
|
|
anonymous from United States
|
|
|
|
'Can't open *.html: Invalid argument'
..
means that it did not find any *.html files. Maybe you're in the wrong folder?
|
|
anonymous from United Kingdom
|
|
|
|
Hi Thanks but i wish it was as easy as that unfortunatly i was in the right folder. so if you have antother tip or suggestion would be much appericated
|
|
anonymous from United Kingdom
|
|
|
|
Hi
The above works fine if i supply a specific file name but not with a *.txt.
hereis what i did
Directory of C:\Documents and Settings\aajind\Desktop\battest
21/02/2006 12:28 <DIR> .
21/02/2006 12:28 <DIR> ..
14/02/2006 10:52 7,957 help.txt
16/02/2006 15:51 346 mynewsam.bat
21/02/2006 12:28 53 sample.txt
21/02/2006 12:28 53 sample.txt.bak
10/02/2006 13:22 33 sample2.txt
14/02/2006 08:23 38 sample3.txt
14/02/2006 10:33 692 testaj.bat
14/02/2006 10:33 692 testaj.vbs
8 File(s) 9,864 bytes
2 Dir(s) 32,098,480,128 bytes free
C:\Documents and Settings\aajind\Desktop\battest>perl -pi -i.bak -e 's/ma/sa/' *.txt
Can't open *.txt: Invalid argument.
C:\Documents and Settings\aajind\Desktop\battest>perl -pi -i.bak -e 's/ma/sa/' sample.txt
C:\Documents and Settings\aajind\Desktop\battest>
ajay.jindle@gmail.com if you can help
Thanks
aj
|
|
anonymous from United Kingdom
|
 |
|
|
I have the same problem 'Can't open *.html: Invalid argument' . The script works in a directory under Linux, but in the same directory ('folder') under WinXP the script throws up the error message. In my Googling I've come across a suggestion that -i doesn't work, but not a clear explanation of why and what the workarounds are.
--
Zym
|
|
anonymous from United Kingdom
|
 |
|
|
Found it.
Try perl -pi.bak -e 'BEGIN{@ARGV=<*.html>} s/searchterm/replaceterm/g'
--
Zym
|
|
anonymous from India
|
|
|
|
Can anyone interested to answer me. I have a html file with some text written on it. Can i search for it and retrive more of the details from that html file?
|
|
anonymous from United States
|
|
|
|
sample perl code ---
--replace.pl---
#!/usr/bin/perl
if(-e $ARGV[0])
{
$cmd = 'copy $ARGV[0] $ARGV[0].bak';
`$cmd`;
}
else
{
print 'File does not exist.\n';
exit;
}
open(INPUT,'$ARGV[0].bak') or die 'Cannot open file: $!\n';
open(OUTPUT,'>$ARGV[0]');
while(<INPUT>){
$_ =~ s/$ARGV[1]/$ARGV[2]/g;
print $_;
print OUTPUT $_;
}
close INPUT;
close OUTPUT;
---
call like
perl replace.pl file.html originaltext newtext
----
use at your own risk..
|
|
anonymous from India
|
|
|
|
very useful
|
|
anonymous from India
|
|
|
|
How to modify the given command if my Input String (Finding term) has / ..?
|
2008-12-23, 03:10:30 (updated: 2008-12-23, 03:48:35) |
anonymous from Singapore
|
|
|
|
I tried for a set of text files it did not work.But for a single file it will work
Any suggestions??
-Tina
|
|
|
|
|
The way that Windows expands file names is different from UNIX, which is why you can't use *.html or *.txt with the in-place search and replace. Just use a command-line for loop:
for %x in (*.html) do perl -pi -i.bak 's/searchterm/replaceterm/' %x
|
|
anonymous from United States
|
|
|
|
cool, i just used this to remove some white spaces in a dhtml menu i copy pasted into vi:
sudo perl -pi -i.bak -e 's/\s{0,}(\<.*)/$1/g' dhtml_menu.dhtml
'just imagine an html markup file with 0 to many amount of whitespace before each tag'
kinda ugly but it works !! =)
|
|
ynwovibl from Germany
|
|
|
|
|
|
anonymous from India
|
 |
|
|
@Tina, basic search and replace script can be used for multiple files as well punching with a shell script.
using for loop of bash script
|