Re: newbie sed question
From: jerrygarciuh (designs_at_no.spam.nolaflash.com)
Date: 05/30/04
- Next message: Otto Wyss: "Tutorial and guidelines: A proposal for better OpenSource code (long message)"
- Previous message: jerrygarciuh: "Re: newbie sed question"
- In reply to: Lew Pitcher: "Re: newbie sed question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 May 2004 10:10:47 -0500
Thanks very much for your help! That did the trick!
jg
"Lew Pitcher" <lpitcher@sympatico.ca> wrote in message
news:B5euc.51734$sr3.1547186@news20.bellglobal.com...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> jerrygarciuh wrote:
> | Hi all,
> |
> | Let me start by confessing that I cross posted this to comp.unix.misc
before
> | relaizing that is a very low-traffic group.
> | Mea culpa.
> |
> | Ordinarily I would just do this in Perl but I am trying to strengthen my
> | bash-fu.
> | I want to substitute all occurrences of foo with bar in all files named
> | index.php recursively from my cwd.
> |
> | I tried this:
> |
> | ls -R| grep 'index.php' | sed 's/foo/bar/g'
>
> This pipeline takes the results of
> ~ ls -R | grep 'index.php'
> and gives them to sed as data, so that sed can 's/foo/bar/g' on it.
>
> It does /not/ give sed a list of files
>
>
> | This output to stdin the list of files but apprently did not run them
> | through sed.
> |
> | I see in man sed that sed expects the filename(s) as the last arg so I
> | tried:
> |
> | sed 's/foo/bar/g' | ls -R| grep 'index.php'
>
> This pipeline has sed editing your terminal input, performing
's/foo/bar/g' on
> it, and outputing it to the ls command (which ignores it).
>
> | to no avail.
> |
> | Any advice?
>
> To do what your pipelines attempted to do
>
> ~ for file in `ls -R | grep 'index.php'` ;
> ~ do
> ~ sed 's/foo/bar/g' $file
> ~ done
>
>
> To do what you should be doing
>
> ~ for file in `ls -R | grep 'index.php'` ;
> ~ do
> ~ sed 's/foo/bar/g' $file >$file.xxx
> ~ rm $file
> ~ mv $file.xxx $file
> ~ done
>
>
> | TIA,
> |
> | jg
> |
> |
> |
>
>
> - --
> Lew Pitcher
>
> Master Codewright & JOAT-in-training | GPG public key available on request
> Registered Linux User #112576 (http://counter.li.org/)
> Slackware - Because I know what I'm doing.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
> iD8DBQFAuW4IagVFX4UWr64RAiHcAKCp3PYr5tLIlhwzu+GZTj+Toi9JDQCgnsel
> DVoE4DxVrOxFpMEmSbde3T0=
> =0M2V
> -----END PGP SIGNATURE-----
- Next message: Otto Wyss: "Tutorial and guidelines: A proposal for better OpenSource code (long message)"
- Previous message: jerrygarciuh: "Re: newbie sed question"
- In reply to: Lew Pitcher: "Re: newbie sed question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]