Awk/Sed Filehandler question 
Author Message
 Awk/Sed Filehandler question

Hello,
I am trying to replace a name in 100's of .csh scripts.  The person no
longer works with us and we need to exchange his name for a new
person.  The script names can't change so what I am basically asking
what is the best way to use awk/sed to rewite the script, making the
change and keeping the original name??

TIA,
Nick



Mon, 17 Oct 2005 22:36:07 GMT  
 Awk/Sed Filehandler question

Quote:

> Hello,
> I am trying to replace a name in 100's of .csh scripts.  The person no
> longer works with us and we need to exchange his name for a new
> person.

Poor him, being erased just like this :-)

Quote:
> The script names can't change so what I am basically asking
> what is the best way to use awk/sed to rewite the script, making the
> change and keeping the original name??

for i in *.csh; do
  tmp="$i#"
  sed 's/Nick/Laurent/g' $i > $tmp
  if ! cmp -s $i $tmp
  then
    # file has changed, create a backup and replace original file
    mv $i $i~
    mv $tmp $i
  else
    # file hasn't changed, remove our temp.
    rm -f $tmp
  fi
done

Laurent



Tue, 18 Oct 2005 00:12:18 GMT  
 Awk/Sed Filehandler question

Quote:

>Hello,
>I am trying to replace a name in 100's of .csh scripts.  The person no
>longer works with us and we need to exchange his name for a new
>person.  The script names can't change so what I am basically asking
>what is the best way to use awk/sed to rewite the script, making the
>change and keeping the original name??

Since you want to re-write the files in place, I would suggest doing it in
"ex".  But that would be OT in this NG (just as would be the inevitable
shell solutions).

In (g)awk, I would do:

    { x[NR] = gensub(/John Doe/,"Mary Smith","G") }
    END { for (i=1; i<=NR; i++) print x[i] > ARGV[1] }



Tue, 18 Oct 2005 03:20:51 GMT  
 Awk/Sed Filehandler question

Quote:

> Hello,
> I am trying to replace a name in 100's of .csh scripts.  The person no
> longer works with us and we need to exchange his name for a new
> person.  The script names can't change so what I am basically asking
> what is the best way to use awk/sed to rewite the script, making the
> change and keeping the original name??

Others have answered your question, but
maybe it is time to wonder whether your
approach of burying employees' names
in hundreds of scripts is a good idea.

You might want to consider creating
a special account for the purpose of
running these scripts, in the same way
you email your expense claims to
"expenses" rather than to Susan in
accounts.

John.



Tue, 18 Oct 2005 04:44:20 GMT  
 Awk/Sed Filehandler question

Quote:
> I am trying to replace a name in 100's of .csh scripts.  The person no
> longer works with us and we need to exchange his name for a new
> person.

You mean deny him credit for his labor?  Surely not that ...

Quote:
> The script names can't change so what I am basically asking
> what is the best way to use awk/sed to rewite the script, making the
> change and keeping the original name??

Blasphemy, perlhaps,

  perl -p -i -e 's/John Doe/Mary Jane/' *.csh

but the edits are inplace.

--
David Thompson



Fri, 21 Oct 2005 13:52:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Newbie awk (sed??) question, regular expressions

2. A very simple question on SED or AWK for a GURU, and an enjoyable problem

3. awk or sed: basic? question

4. 2 questions from book sed and awk programming

5. Question: How to remove END OF LINE using AWK or SED

6. awk vs. sed question

7. Sed/awk question

8. Sed/awk question Answered!

9. sed, awk, perl

10. SED to AWK...???

11. Extracting hyphenated words using sed/awk

12. Need help with sed or awk !!

 

 
Powered by phpBB® Forum Software