For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2005 > Delete a char from file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Delete a char from file
Sridhar Reddy

2005-10-19, 6:56 pm


Is there any way to delete a character from a file from command line

Let me explain..

I have a symbol % in file in many places. I want to remove
it from the file. Here I don't like to write a script just looking for a
command to delete the character from the file.




Thanks,
Sridhar Reddy


Paul Lalli

2005-10-19, 6:56 pm

Please do not reply to an existing posting to start a new thread.
Instead, start a fresh thread. Thank you.

Sridhar Reddy wrote:
> Is there any way to delete a character from a file from command line
>
> Let me explain..
>
> I have a symbol % in file in many places. I want to remove
> it from the file. Here I don't like to write a script just looking for a
> command to delete the character from the file.


You want to remove *all* instances of '%' from the file?

perl -pi.bak -e's/%//g' file1.txt files2.txt

This will open file1.txt and file2.txt, save backup copies as
file1.txt.bak and file2.txt.bak, read each line from both files, remove
all % characters from those lines, and print the results back to the
original files.

Read more about the -p and -i switches in:
perldoc perlrun

Paul Lalli

Varghese Mathew

2005-10-19, 6:56 pm


> I have a symbol % in file in many places. I want to remove
> it from the file.


can you try this?

perl -pi -e 's/%//g' filename

Varghese
ps-ax.org

Sridhar Reddy wrote:

>Is there any way to delete a character from a file from command line
>
>Let me explain..
>
> I have a symbol % in file in many places. I want to remove
>it from the file. Here I don't like to write a script just looking for a
>command to delete the character from the file.
>
>
>
>
>Thanks,
>Sridhar Reddy
>
>
>
>
>

John W. Krahn

2005-10-19, 9:55 pm

Sridhar Reddy wrote:
> Is there any way to delete a character from a file from command line


Yes.

> Let me explain..


Please do.

> I have a symbol % in file in many places. I want to remove
> it from the file. Here I don't like to write a script just looking for a
> command to delete the character from the file.


No script, ok.

tr -d % < oldfile > newfile

sed s/%//g oldfile > newfile



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com