The following Perl one-liner will do what you need
perl -n -e 's/(.{8,8}).(.*)/$1$2/;print ;'

The first set of parentheses strips out the first 8 characters, the second set strips out everything after the 9th character which is lost.
My test line was:-
(echo "1234567890";echo "abcdefghijkl")|perl -n -e 's/(.{8,8}).(.*)/$1$2/;print 
;'

The two echo statements are in parentheses to keep them within the same sub-shell.

I'm assuming all along you are running a *nix type system.
--
Andrew in Edinburgh,Scotland

On Tue, 5 Aug 2008, Chris Charley wrote:


----- Original Message ----- From: "Chris Charley" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Tuesday, August 05, 2008 10:45 PM
Subject: Re: question about text operation using regex.



----- Original Message ----- From: ""Remy Guo"" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "Perl Beginners" <beginners@perl.org>
Sent: Tuesday, August 05, 2008 10:14 PM
Subject: question about text operation using regex.


hi all,
i have a txt log file and i want to delete the 9th character of each line.
how can i do it using regex?...thanks!

-Remy


Ooops. Sent it to the poster by mistake.

You could do it from the command line

perl -pe "8 < length && substr $_,8, 1, ''" logfile.txt > altered_file.txt

Chris


Just to clarify the substr function here. Following the 1, are 2 *single* quotes. This assigns the empty dtring to the 9th position of the string, effectively eliminating the 9th character. Chris



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to