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

Notices


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

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:

Code:
http://user:pass@whatever.whatever.com/
I want to only have
Code:
user:pass
Can anyone help?
 
Old 01-10-2007, 12:57 PM   #2
FnordPerfect
Member
 
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:

Code:
#!/bin/sh

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

while read a;
do

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

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

* Make it executable with chmod +x url-extract.sh

* Give your filename as the first argument:
url-extract.sh 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
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 282

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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 12:10 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
Open Source Consulting | Domain Registration