LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   An easy way of deleting lines from multipe files? (https://www.linuxquestions.org/questions/linux-general-1/an-easy-way-of-deleting-lines-from-multipe-files-165395/)

delawhere 04-02-2004 11:19 AM

An easy way of deleting lines from multipe files?
 
I have multiple files that contain email addresses. One per line. I would like to remove a patiular email address from each file but I'm not sure the quickest way to do this.

If I do
grep user@here.com *
I get
file1:user@here.com
file2:user@here.com
file9:user@here.com

and so on.

Is there a way to somehow remove the email address from the with grep or should I try some other command?

Thank you for any help or suggestions.

paulsm4 04-02-2004 11:39 AM

Hi -

Try this:

1. Type in the following shell script# Declare a temp file
<= EXAMPLE: "vi script1.sh":
TMP=/tmp/$$.tmp
ADDR=myaddress_remove

# Make sure we can write to it (we'd be sad if we couldn't...)
touch $TMP
if [ ! -w $TMP ]; then
echo "WARNING: Unable to write to $TMP"
ls -l $TMP
exit 1
fi

# OK: we're ready to remove the address "cow" using the tool "grep -v"
for i in file1 file2 file3; do
echo "Processing file $i..."
grep -v $ADDR $i > $TMP
mv $TMP $i
done

echo "Done."

2. Substitute your file names and the e-mail address you want to remove

3. Set the "execute" permissions on your script
<= EXAMPLE: "chmod +rw script1.sh"

4. Run it
<= EXAMPLE: ./script1.sh

Unfortunately, there's no one-line/1 command that I know if.

"hope that helps .. PSM

delawhere 04-02-2004 11:58 AM

Thank you very much for your help!!


All times are GMT -5. The time now is 10:39 PM.