Newbie question: how to replace a bunch of text in a file?

Good afternoon,
I have a very stupid problem here: I want to replace text in a file.
At first glance, this is very simple: just do:
sed -e 's/letter_a/alpha/g' test.txt > test2.txt
and the word "letter_a" will be replaced by the word "alpha" everywhere in the file "test.txt" and the results will be placed in file "test2.txt".
However my problem is a bit more complex:
I want to do different replacements in one file.
If I do:
sed -e 's/letter_a/alpha/g' test.txt
then the result will be shown on my screen, but I want the results to be stored in my file "test.txt".
I have already tried to do:
sed -e 's/letter_a/alpha/g' test.txt > test.txt
but this simply empties the file "test.txt".
As I have more than 50 replacements to do, I cannot do something like:
sed -e 's/letter_a/alpha/g' test.txt > test1.txt
sed -e 's/letter_b/beta/g' test1.txt > test2.txt
sed -e 's/letter_c/gamma/g' test2.txt > test3.txt
+...+
mv test50.txt test.txt
rm test1.txt
+...+
rm test50.txt
(It's possible in theory, but it's really too much work)
Do you know an easy command that does the following:
Replace "letter_a" by "alpha" in <filename> (without needing to specify another file where the output will be written)?
Thanks
Dominique
Edited by: scampsd on Oct 5, 2011 5:17 PM

Why don't you write a wrapper script that renames the input file to a temp file and run the sed to the original name. Something like:
<pre>
#!/bin/sh
# $1 = old string
# $2 = new string
# $3 = input/output file
cp -p $3 $3.zz$$ # preserves i-node of file
sed -e s/"$1"/"$2"/g < $3.zz$$ > $3
rm $3.zz$$
</pre>

Similar Messages

  • Newbe Question: How to get the Workflow Name to a WS* number?

    Hi All
    Just a short question:
    I have a whole bunch of WS9*** numbers and now I am supposed to find the corresponding WorkFlows in a system (from a business perspective). The problem is that I have no clue on how to do this as I am reale new to WorkFlows.
    Is there anybody who can help me out?
    Thanks,
    Regards,
    Minima

    Hello,
    If you have access to PFTC_DIS, choose "Workflow template" for Task type and do a list of values on the Task field (which has the WS* number, but without the WS). This will give you the full list.
    If you don't have access to PFTC_DIS, but do have access to SE16 or SE12, look in table
    HRS1000 where OTYPE = WS and LANGU = EN.
    regards
    Rick Bakker
    Hanabi Technology
    Edited by: Rick Bakker on Dec 15, 2008 12:58 PM

  • Newbie Question:  How much computer do I need?

    Newbie Question:
    I would like to use MainStage 3 in a live performance environment to play bars, parties, etc.  I'm not looping, using it to playback recordings, processing outboard equipment or vocal processing.  I want to stop carrying Rolands, Nords, Korgs, etc and get to a controller and a rack with a Mac Mini in it.
    I tested a download of Mainstage 3 on my home Mac Mini (late 2012, 3.5 Ghz i5, 4GB RAM, 500GB drive) and it seemed to run fairly well.  $30 well invested so I trekked forward... I purchased a Mac Mini (late 2009,  2.52GHz Core 2 Duo, 6GB RAM, 128GB SSD) for $200.  I started to do more elaborate keyboard setups to see how the CPU would hold up.  It typically runs from 30% to 50% of capacity (CPU and Memory)  It actually boots and runs better than the i5.  I hear the occasion gitch, but it actually seems to be getting better in time (or I'm rock and roll deaf.
    I got a rack, an Airport Express, a Radial USB interface and a Nektar Panorama P6.  It's starting to get expensive, but I'm emboldened by the actual quality for the sound and the flexibility of arranging for live performance.  What used to take me two and three keyboards to play, I can now fit on one performance patch.
    OK, now the question... am I at the limits of this little Core 2 Duo?  Should I upgrade the i5 with more RAM and a bigger SSD and use that?  Should I get a new(er) i7 and bite the $1,500 bullet for the additional RAM and SSD?
    I see that most of you are running pretty nice Macbook Pros with i7 and lots of everything.  My needs are modest; am I OK? 
    BTW, I want to run a Mac Mini in a box because I don't want to carry a laptop out in the open.  If I was doing bigger shows I wouldn't care but I play some rowdy bars and constantly have folks hanging off me while I'm playing.  It's fun, but hard on gear.  If you can't drop it or dip it in beer, it won't last long where I work.
    Matt Donnelly

    Rule of thumb: newer and faster is better. But, depending the complexity of your needs you may be OK with an older Mac. Some glitches that happen in a live performance are due to loss of communication with USB or Firewire inputs, so make sure they're secure. I recently upgraded from a 2010 Mac Mini 2.6 dual core with 16 GB RAM, which was used live for nearly four years, to the latest Mac Mini 3.0 i7 with 16 GB RAM and a 500 GB SSD. I was getting an occasional stuck note with the older one. The new one is rock solid. Some of my patches may have up to a dozen channel strips mapped to three keyboards. The Mini is mounted in a rack next to a MOTU Ultralite Hybrid. It is a good idea to map a panic button on your keyboard to controller # 123(all notes off). Also, you might want to invest in a battery backup power supply(APC, Cyberpower, etc.-$40-$60) to protect your Mac against power loss, which can damage you hard drive.

  • A newb question - How do I get iTunes to stop DELETING things from my iPod?

    I just got my PC back up and running, went to use my brand new iPod that was loaded with music/movie/podcasts from my laptop, I install iTunes on the PC, get everything set to my account and then take a look at my iPod only to find EVERYTHING has just been deleted.
    So far I hate iTunes and I truly hate the fact that I cannot just drag and drop files onto my iPod.
    Is there a way to lock files so they do not get deleted? Now all the stuff I have purchased cannot be downloaded again, another stupid idea. Once I pay for something I should be able to download it to the same iPod as often as I need.
    What truly ***** is I am a technogeek and have been an IT person for a long time, just when I think I understand how this software works, BAM it deletes all the files on my iPod.
    Is there any other decent software out there that I can use besides iTunes?
    I think you get the idea, I am frustrated and I know it is something simple that I am missing or overlooking. I guess I have to go buy iTunes for Dummies huh
    Any help or information that anyone can offer would be wonderful.
    Thanks,
    John W
    Custom   Windows XP Pro   First Gen iMac

    thanks
    I will still look for a different program.
    The other programs (like Anapod) are all Windows Explorer based and thus only work decently on very small music collections (e.g., less than 500 tracks or so). If you have a substantial collection, these schemes quickly become more trouble than they are worth because you must track everything manually or indirectly.
    My library is medium sized at 17,500 tracks (still under 75GB, just barely) and I could never manage it without a database like iTunes. If I had a large collection this advice would go double.

  • Newbie question - how to add a computer not on your network?

    We purchased the ARD 3.0 for our networked Macs and so far it's been working fine. But we also have a remote user we'd like to add. This person is using a cable modem to connect to our VPN now but is moving and may have to use dial-up for a while.
    So, how do I add them to this list? Get their IP address? What if the IP address changes?
    Thanks

    "So, how do I add them to this list?"
    "File" menu --> Add by address.
    But you should forget about supporting this user if they have a dialup connection, as it is far to slow to do 95% of ARDs tasks...especially control and observe.
    "What if the IP address changes?"
    Set up the computer with a dynamic hostname at dyndns.com

  • How to replace a line ina text file using java?

    Hi ALL,
    Does anybody know how to replace a line in a text file uisng java.

    use this thing:
    http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    open the file,
    read its contents, replace the text you need in the contents, set the contents back into the file.
    it takes care of the IO for you.

  • How to use automator to convert text to audio file

    I have a MS Word file which I would like to convert to an audio file using the text to audio file script available in automator. Forgive my ignorance but I am having difficulty in finding how to do this.
    Can anyone give me a step by step approach.
    Thanks
    Alain

    One way:
    1. Get Selected Finder Items
    2. Open Finder Items
    --Open with: TextEdit
    3. Get Contents of TextEdit Document
    4. Text to Audio File

  • (Bash) How to set a variable with text from a file? [SOLVED]

    I'm having a little problem.
    I have textfile with a single line of text. What I want to do is set a variable with that line of text. How do I go about doing that?
    A simple var="text" wont work in this case, since the text in the file changes with another script of mine.
    Thanks in advance.
    Last edited by Aziere (2007-03-27 09:07:03)

    if you have a file with more than one line but you only want the first line you could use 'head'
    VAR=`head -n 1 file`
    Last edited by SiD (2007-03-27 05:58:33)

  • Newbi Question:  How does one create a similar page to this using APEX 3.1?

    Hi,
    I am trying to create a help document with screen shoots inside our APEX web application and I am hamstrung by the type of Region and Item objects available to me. When I tried to create HTML region I was limited to how much html characters I can put in the source. When I look into the item menu nothing seems to allow me to stick in large chunk of HTML code either.
    A little searching on this forum and I came across this page: http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm#t
    It is exactly the type of page I want to create with lots of text and screen shots and I presume that it is built within APEX? So my questions is: How did they do this? Did they use tools available within APEX or some external tool? Was all this outputted using BLOB and Htp("") and PL/SQL? I am trying hard to avoid having to do that.
    I was also unable to stick in an in image into my page using instruction from http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/ui.htm#CBBHGJCH which left me pretty frustrated. (external amazon gif worked).
    Thanks for any help,
    Wayne

    Wayne,
    I am glad that you got images to display. I am not sure what kind of html report you want to display, there is a limit of number of characters in a region its 32767 characters, so if you want to display large html file you can create html region with no template and limit each region to 30,000 characters and create as many region as you want.
    If you want to display data from any table ( as per the first url) you can create SQL reports, something like
    select ename
         , deptno
         , sal
         , case
              when ename = 'SCOTT' then '<img src="#WORKSPACE_IMAGES#us_flag.gif" alt="Image Title">'
              when ename = 'SMITH'  then '<img src="#WORKSPACE_IMAGES#chants.gif" alt="Image Title">'
              when ename = 'MARTIN' then '<img src="#WORKSPACE_IMAGES#cloche.gif" alt="Image Title">'
              when ename = 'MILLER' then '<img src="#WORKSPACE_IMAGES#chandelles.gif" alt="Image Title">'
              when ename = 'JONES' then  '<img src="#WORKSPACE_IMAGES#shoe.gif" alt="Image Title">'
              else '<img src="#WORKSPACE_IMAGES#hallo.gif" alt="Image Title">'
         end  image
    from empThanks,
    Manish

  • Newbie question:  How do I set the input for a series of audio recordings to be different, if I only have a 2 channel interface?

    I am using a 2 channel interface (Apogee Duet) and I can record a voice and guitar track fine.  My question is how do I record a third audio track after the fact?  It seems when I attempt to record an additional track, say bass for example, Logic treats it as though it is on input 1 or 2 (which hardware wise it is of course) and merges them in a sense.   I don't know how to make it a seperate independant track, despite the fact that it was recorded through an input that I also used to record something else on a diferent track.
    Thanks in advance, I very much appreciate any help.

    Thanks for the response.  I know it sounds ridiculously basic.  Yes I am creating a new track and selecting it.  The third track appears in the arrange window, but changes to, for example, the third track affect the 1st.  Doesn't matter if it's a 1/4 inch guitar or XLR mic.  Yes I'm listening to the headphone output from the Duet.
    I think the fundamental problem is my not understanding something about mono/stereo, or prehaps input and output settings.  I just can't seem to find the appropriate controls/settings.

  • Newbie question - how to save images out of an fla file

    I have what I'm sure is a very basic flash question. I have a flash movie (swf) and the accompanying fla file. I can open the fla file, and see all the images used in the file (symbols in the library), but how can I export or save one of these images separately from flash?

    you can right click, copy an image and then paste it into your choice of photoediting software.

  • Newbie question: how to monitor cluster disk drive free space

    ok folks, it is a really painful process for me to use SCOM2007R2 and I figure it might be easier if I start to ask concrete questions.
    1. I have a cluster server and I know some drives have only 10MB and they are not changing at all as I fixed them.  How can I use Monitor/Rules so that I could receive Alert?  I was told by our admin that SCOM only got triggered if status got changed
    In my case, since the drive space will never get changed (fixed to 10MB left), I will never receive alert???
    cheers
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    "Logical disk free space" is the monitor that will be monitoring this.
    Yes, SCOM will send alerts only when the Mbytes and % values of the free space ; mentioned in the monitor are met. You can configure this monitor by setting up correct Mbytes and % values   to change the state of this monitor and thereafter you
    will receive the alerts from this monitor.
    Hope this helps.
    Thanks, S K Agrawal

  • Newbie Question: How to organize program with lots of components

    Hi,
    After struggling through the basics of Swing programming, I've finally got my application to look like what I want. Now I have to deal with all the inputs and variables (which is the hard part ^_^).
    I wonder how people usually organize numerous components and action listeners? I have a lot of fields that have to be synchronized frequently with a hardware device, and they are also adjustable by a number of menus.
    Currently I've just stuffed all the listeners and actions as inner classes in my main display frame. I am hoping to create a separate class that can manage all these actions, or a more elegant way to organize my program.
    For now I'm reading up on MVC (Model View Controller). Is that a good place to start? Or how about XML?
    I know this isn't a very specific question, but I'd appreciate a push in the right direction ^_^
    Thanks!
    Cindy

    I would look at MVC and its part - Observer pattern.
    Denis Krukovsky
    http://dotuseful.sourceforge.net/
    http://dkrukovsky.blogspot.com/

  • Newbie Question: How to find Forms/Reports Server Version

    Hello,
    Is there a way to easily find out what is the patchset installed for the Forms and Reports Server. I know that presently using AS 9i rel1 and Forms 6i, but how do you find out more information on the installed patches on Windows? thanks

    Please see these threads.
    how to find the developer version
    Re: how to find the developer version
    Report Builder version
    Re: Report Builder version
    Form patch set level
    Re: Form patch set level.
    Always search the forum before posting similar questions.
    Thanks,
    Hussein

  • Newbie Question: How Freeze Dimension Settings work?

    Dear all:
    For some reason, I couldn't figure out how "Freeze Dimension Settings" of dynamic template work on overriding members. I looked into both row and column EVEXP function and in the data region EVGTS, and none of the Current View column under Freeze Dimension Settings was ever selected. 
    Can someone clue me out? Thanks a bunch!
    Sincerely,
    Brian

    Hi,
         The "Freeze dimension section" is getting all the dimension values from CV. This information is used into "Expansion Settings" for the Member definition (using VLOOKUP function - freeze dimension is view as an array of dimension and values and the value is taken according with the dimension selected into Dimension field).
    Hope this can help you to understand better how dynamic templates is built.
    Regards,
    Mihaela

Maybe you are looking for

  • Time capsule and Seagate external hard drive, Time capsule and Seagate external hard drive

    I have Mac Book Pro with Retinal Display Mac OS X 10.8.2 connected Time Capsule 1TB using wireless network. I recently purchased Seagate Backup Plus 3TB and I connected to TC. However, I cannot find the Seagate drive on the network or via Aiport Util

  • ITunes Air Play Not Working

    Windows 7 - iTunes 12 iTunes has no issues and plays all content well I am trying to stream content to an Apple TV (latest generation I think, I just got it from Staples) I've removed iTunes, including all libraries, registry entries, and all related

  • Updating music on 2nd computer from Purchased music

    I want to listen to my purchased music on my second computer. I went to the "advanced tab" and clicked on check for purchased music, but I only get 7 of my 100 or more songs that I purchased on my other computer - I am using the same login on both co

  • Banner ad with different links?

    Hi all, Is it possible to create a banner in FW that transitions between two states and to have each state link to a different page? I tried to accomplish this with hotspots, but clicking on the banner would direct to the same page for both stages. T

  • Why does screen go black using brush tool?

    When the brush tool is activated (using a personal watermark) and I move around the screen, particularly outside of the photo area workspace, the screen goes black for 2 seconds and then comes back on whether or not I move back into the photo.  Haven