LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2004, 01:44 AM   #1
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Rep: Reputation: 0
Find & Replace


I'm at the end of my rope here. I'm taking this rediculous class that is using this terrible book and the teacher seems to just like to assign problems that arent' covered by said book.

I need to search a file, pull out all the vowels and turn them into numbers. So a-->1, e-->2, i-->3, etc... It also has to be a single pipeline. So no shell scripts.

I've searched google and havn't found anything yet. So I'm giving asking a shot.
 
Old 04-09-2004, 04:41 AM   #2
iluvatar
Member
 
Registered: Jul 2003
Location: netherlands
Distribution: debian
Posts: 403

Rep: Reputation: 30
you must use the sed command. this command:

sed s/"a"/"1"/ file.txt > file2.txt

will replace all 'a' characters into '1' characters from file 'file.txt' and it writes the new file with changed characters to 'file2.txt'. you may do much more complicated things with sed, wich I don't know read the man page (man sed) for more information!

greetinz,
-= iluvatar =-
 
Old 04-16-2004, 01:08 AM   #3
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Original Poster
Rep: Reputation: 0
Ahh thanks. No wonder I never found it in the given chapters...sed is the next section :/
 
Old 05-03-2004, 12:20 AM   #4
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Original Poster
Rep: Reputation: 0
Here's what I ended up using for those who are interested...

Code:
sed -e 's/a/1/g' -e 's/e/2/g' -e 's/i/3/g' -e 's/o/4/g' -e 's/u/5/g' file1 > file2
Now, what I have to do is instead of find and replace I need to find and delete. So find all the vowels and delete them. So far I can find each vowel and replace them with a space but there should be a way to delete each one, yeah?
 
Old 05-03-2004, 12:35 AM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
sed 's/foo//g'
replaces 'foo' with nothing. It only put a space if you tell it to. 's/foo/ /g'

Shouldn't really be asking homework questions and I shouldn't be answering, but it's not like this one is really a major giveaway.

For the first
sed 's/[aeiou]/1/g'
would have been easier unless they have to be different numbers and then
sed 's/a/1/g;s/e/2/g;...'
would have been slightly. Probably even easier varieties, but my sed sucks.
 
Old 05-03-2004, 02:37 PM   #6
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Original Poster
Rep: Reputation: 0
Heh, thanks. I know I shouldn't be asking and that was the last time. I thought I had it after that first question but I couldn't find anywhere in the man pages that just said I could put nothing and get it to erase.

Now I'm getting the hang of it at least. Next up I get to work on awk.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace happy78 Programming 11 09-10-2005 10:21 AM
Find & Replace Carriage Return in ooo linuxian Linux - Software 1 04-09-2005 05:43 PM
Help - how to find and replace in Vim stardotstar Linux - Software 7 10-14-2004 11:31 PM
find with grep and replace it dominant Linux - Newbie 4 03-03-2004 01:11 PM
Find and Replace? duerra Linux - General 9 01-28-2004 04:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 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