LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-02-2008, 11:01 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 73
Force Script (Bash) to Edit File?


I have a bash script that creates an account and also it does the following:

Code:
 echo "$USERNAME@youremail.com" >> "$alias_file"
        newaliases
This takes the newly created account and also adds their email address into the specified text file and then runs the "newaliases" command.

This works perfect however I have a delete_user.sh script and I would like to know how I can remove the users email address from the file using the script? I don't know how that would look like or how that needs to be added into the "delete_user.sh" script.

Does anyone know how the script can open the text file, delete the specified entry, save the file, and then run the "newaliases" command?

Thanks for any help!
 
Old 10-02-2008, 11:07 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

# sed -i /^$USERNAME@youremail.com/d "$alias_file"

will remove the line. Then run newaliases as before.
Test before use - 'sed -i' can clobber files if used without care.

Dave
 
Old 10-02-2008, 11:43 AM   #3
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 73
Did I do something wrong in testing this?

Code:
cwilliams@tunafish:~$ touch test
cwilliams@tunafish:~$ echo this is a test >> test
cwilliams@tunafish:~$ cat test
this is a test
cwilliams@tunafish:~$ sed -i/^this is a test/d "test"
sed: -e expression #1, char 1: unknown command: `i'
cwilliams@tunafish:~$ cat test
this is a test

Last edited by carlosinfl; 10-02-2008 at 11:44 AM.
 
Old 10-02-2008, 11:57 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Wasn't accounting for spaces in email addresses

The general form would be:
Code:
sed -i "/^this is a test/d" test
Watch for special characters in your expression - if there's a '/' or a '"' or anything like that, it'll bork the expression. Quote carefully, but for normal email addresses the above should be fine.

Dave
 
  


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
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 11:23 AM
bash shell script find and edit fields in a file hchoonbeng Programming 9 10-29-2008 03:13 AM
Bash script to edit text file snowman81 Linux - Desktop 2 01-10-2007 04:33 PM
how can i EDIT file by BASH Guru Mind Programming 27 03-28-2006 04:38 AM
Bash script to edit passwd without Root password? NetFlash Linux - Newbie 2 11-29-2003 05:22 PM


All times are GMT -5. The time now is 01:24 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration