LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-02-2004, 11:19 AM   #1
delawhere
LQ Newbie
 
Registered: Feb 2004
Posts: 3

Rep: Reputation: 0
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.
 
Old 04-02-2004, 11:39 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 04-02-2004, 11:58 AM   #3
delawhere
LQ Newbie
 
Registered: Feb 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you very much for your help!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting files in C monil Programming 4 03-13-2005 10:33 AM
Deleting files! a_priebe47 Slackware 6 10-17-2004 09:58 PM
Extracting Lines from files supreme_command Linux - Newbie 1 05-12-2004 04:21 AM
Deleting files ShakyJake Linux - Newbie 12 05-08-2003 03:07 PM
Deleting files Tingle Linux - Newbie 4 01-16-2003 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration