Replacing text using awk (but in a c shell) 
Author Message
 Replacing text using awk (but in a c shell)

I have a C shell script which takes user input as ...

echo "Enter a Number"
set num=$<

I then want to replace a piece of text in a file with that number.

I was going to use sed to do it, as in

sed 's/SysReleaseNumber/$num/' data    (where data is the file)

but that just replaces the text with the text '$num'.
and i dont think there is a way of doing it with sed.
(correct me if Im wrong).

so can awk be used ?

Thanks in advance,
Alan



Sat, 19 Feb 2000 03:00:00 GMT  
 Replacing text using awk (but in a c shell)

Hello Alan,

Quote:

>I have a C shell script which takes user input as ...
>echo "Enter a Number"
>set num=$<
>I then want to replace a piece of text in a file with that number.
>I was going to use sed to do it, as in
>sed 's/SysReleaseNumber/$num/' data    (where data is the file)
>but that just replaces the text with the text '$num'.
>and i dont think there is a way of doing it with sed.
>(correct me if I'm wrong).

<Correction>

The only problem with what you have written is that you have
used the single-quote character (') instead of the double-quote
character (") to surround the sed command.  In the shell, the
single-quote characters remove the metacharacter status of
things like the dollar character ($), and others; whereas if
you use the double-quote character instead, then the variable
substitution from your "$num" parameter will be allowed to
take place, and your sed command should work perfectly

</Correction>

Quote:
>so can awk be used ?

Yes, but that's another story:

Quote:
>Thanks in advance,
>Alan

Best regards,

Lawson Hanson



Sat, 19 Feb 2000 03:00:00 GMT  
 Replacing text using awk (but in a c shell)

This is a multi-part message in MIME format.
--------------A1608DC19D885CE84A6DBF9B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Quote:

> I have a C shell script which takes user input as ...

> echo "Enter a Number"
> set num=$<

> I then want to replace a piece of text in a file with that number.

> I was going to use sed to do it, as in

> sed 's/SysReleaseNumber/$num/' data    (where data is the file)

Use double quotes (") and the $ reference will be expanded.  Single and
double quotes do notbehave the same in UNIX shells.

Quote:

> but that just replaces the text with the text '$num'.
> and i dont think there is a way of doing it with sed.
> (correct me if Im wrong).

> so can awk be used ?

> Thanks in advance,
> Alan

--

Information Systems Architect/Webmaster
The Boeing Company/McDonnell Douglas Aerospace/Huntsville
(205)922-7589  FAX:(205)922-4890

--------------A1608DC19D885CE84A6DBF9B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Burleson, John
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Burleson, John
n:              Burleson;John
org:            The Boeing Co. - McDonnell Douglas Aerospace
adr:            689 Discovery Dr.;;MS 32C1;Huntsville;AL;35806-2804;USA

title:          Webmaster - Advanced Software Systems
tel;work:       205-922-7589
tel;fax:        205-922-4890
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
end:            vcard

--------------A1608DC19D885CE84A6DBF9B--



Sat, 19 Feb 2000 03:00:00 GMT  
 Replacing text using awk (but in a c shell)

                        SED is more versatile
                  when it comes to rearrangin text

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            my !  my!  my !
        that is the kind of problems seders help each other with.
                     join seders now !  email moi !

    for a 1stop sed needs, join seders, the informal sed mailing list.      
    sed is literate.  sed knows 4 R's: read, 'rite, 'rithmetic, recur.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                        sed informal mailing list

    Of abpit half a dozen sed studs known to sedkind, seders has 3, in
                     usa     portugal   taiwan

                               -----

                   sed web pages (in 5 countries)

http://www.wollery.demon.co.uk   seders grab bag (seders official web page)
                                                              seder  Casper
http://www.cis.nctu.edu.tw/~gis84806/sed-script-e.html      seder in taiwan
http://www.math.fu-berlin.de/~guckes/sed/          seder, Herr Guckes
http://www.math.fu-berlin.de/~leitner/sed/          seder, Herr von Leitner
http://www.dbnet.ece.ntua.gr/~george/#seders  seder, engineer, Dr2b Yiorgos
ftp://olivia.inesc.pt/pub/users/cdua/scripts/sed         the great sed stud
ftp://olivia.inesc.pt/pub/users/cdua/scripts/sh   seder Carlos J. G. Duarte

                                ----

             my favourite DOS/UNIX sed15 (with C source)
(easily compilable for UNIX.  has friendly extenstions/relaxations like hex)
 ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15.zip
 ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15x...

Directory: /pub/systems/pc/simtelnet/msdos/txtutl/
Filename    Type Length  Date    Description
===============================================================================
sed15.zip    B    62082  910930  Unix-compatible streaming editor v1.5 TC src
sed15x.zip   B    20300  910930  Unix-compatible streaming editor v1.5 EXE/docs

              sed15.zip has C source, compilable for UNIX.

             Also, check simtel for u-sedit. has nice docs.

                                ----

                O'Reilly sed books http://www.ora.com
1- sed and awk 2nd edition         by   Dale Dougherty  +  Arnold Robbins
        (mostly for awk)
2- mastering regular expressions   by          Jeffrey E. F. Friedl
        (mostly for perl, emacs, awk.  but touches on sed)

                                ----
                   newsgroup alt.comp.editors.batch      
      though seders news group, alt.comp.editors.batch deals with
batch, AI, data warehousing, OLAP, computer security, filters, linguistics,
      awk, perl, unix, computer seminars, CFP, etc (even sed)

           started by a seder, PhD2b, engineer, the hawk
                         Yiorgos Adamopoulos.    

          most newsfeeds do not carry alt.comp.editors.batch
          but everyone can get it via  dejanews (and others)
  you can even follow up, reply to the poster, etc.  dejanews is great.
             (then he sed: not by sed alone ... lives man)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+



Sun, 20 Feb 2000 03:00:00 GMT  
 Replacing text using awk (but in a c shell)

Quote:
> sed 's/SysReleaseNumber/$num/' data    (where data is the file)
> but that just replaces the text with the text '$num'.

"Doctor, Doctor, it won't work if I use quotes!"
"Then don't use them."


Sun, 20 Feb 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Window's 2000 Global Find and Replace Solution using awk

2. using awk in a shell script...

3. Substituting single quotes from Perl via shell using awk and gsub

4. Getting A Day Using AWK or A Shell Script

5. How to replace or create a file using the open/create/replace.vi

6. replacing the windows shell with ACL4WIN version 3

7. Outputting info from awk and using the info to name the awk output file

8. Replacing a string from an input file within awk script

9. How to replace one or two words with one word with one line of awk code

10. 2-file awk search-and-replace

11. replace variable with awk

12. Sed/AWK - replace positions in multiple lines.

 

 
Powered by phpBB® Forum Software