Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Desktop
User Name
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.


  Search this Thread
Old 01-10-2007, 12:40 PM   #1
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 240

Rep: Reputation: 30
Bash script to edit text file

I have a text file that is too big to edit by hand and I want to create a simple little script that deletes part of the entry and leaves the rest.

For example, every line has something like this:

I want to only have
Can anyone help?
Old 01-10-2007, 12:57 PM   #2
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
This is not very smart, but might do the trick:


if [ -z $1 ]; then
        echo "Needs filename as argument."
        exit 1
elif [ -f "$1" ]; then

while read a;

  echo "$a" | sed -e "s+http://++" -e "s+@.*$++g"

done < "$fname"
* Save this as a shell script of a name you like, e.g.

* Make it executable with chmod +x

* Give your filename as the first argument: filename_that_is_to_big_to_edit_by_hand.txt

and it returns only userass as you wanted
Old 01-10-2007, 03:33 PM   #3
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 240

Original Poster
Rep: Reputation: 30
Ok, I shall give it a shot.

Sweet, it worked.

Last edited by snowman81; 01-14-2007 at 12:46 AM.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM
Change Text-File through bash script arkus Programming 2 12-17-2004 08:48 PM
Need help reading text file in bash script scilec Programming 3 11-25-2004 06:44 PM
Bash script - reading from text file twantrd Programming 4 11-24-2004 12:38 AM > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:38 PM.

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