* Korn shell programming - awk in particular
@ 1997-04-24 4:00 A. Mahendra Rajah
1997-04-25 4:00 ` Bob Vickers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: A. Mahendra Rajah @ 1997-04-24 4:00 UTC (permalink / raw)
I am new to Unix and would like to ask 2 questions:
1) Is there any good book that will teach me shell programming
using the Korn shell?
2) How do I debug this awk problem?
$ x = "this+is+a+line+with+equals"
I am trying to replace all the + characters with spaces.
$ print $x | awk '{ i=gsub("+","",$0) }'
"@awk: There is a regular expression error.
*?+ not preceded by valid expression
The source line number is 1.
The error context is
{ i=gsub("+","",$0) >>> <<<
Any help will be greatly appreciated.
Thanks,
-----------------------
mahendra (A. Mahendra Rajah :: Mahendra @ Meena.CC.URegina.CA)
Systems Manager & Postmaster,
Dept of Computing Services,
University of Regina,
Regina, Sask., Canada.
-----------------------
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Korn shell programming - awk in particular
1997-04-24 4:00 Korn shell programming - awk in particular A. Mahendra Rajah
@ 1997-04-25 4:00 ` Bob Vickers
1997-04-25 4:00 ` Finnbarr P. Murphy
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Bob Vickers @ 1997-04-25 4:00 UTC (permalink / raw)
To: A. Mahendra Rajah
A. Mahendra Rajah wrote:
>
>
> 2) How do I debug this awk problem?
>
> $ x = "this+is+a+line+with+equals"
>
> I am trying to replace all the + characters with spaces.
>
> $ print $x | awk '{ i=gsub("+","",$0) }'
> "@awk: There is a regular expression error.
> *?+ not preceded by valid expression
> The source line number is 1.
> The error context is
> { i=gsub("+","",$0) >>> <<<
>
You can do this at shell level:
$ x="this+is+a+line+with+equals"
$ y=`echo $x | tr '+' ' '`
If you can I would avoid awk. In my opinion (flames to /dev/null please)
it is hideous, and it is pretty unportable (all versions have different
quirks). You are better off learning ksh or Perl.
Bob
--
======================================================================
Bob Vickers R.Vickers@rhbnc.ac.uk
Dept of Computer Science, Royal Holloway College, University of London
WWW: http://www.dcs.rhbnc.ac.uk/%7Ebobv/
Phone: +44 1784 443691
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Korn shell programming - awk in particular
1997-04-24 4:00 Korn shell programming - awk in particular A. Mahendra Rajah
1997-04-25 4:00 ` Bob Vickers
@ 1997-04-25 4:00 ` Finnbarr P. Murphy
1997-04-25 4:00 ` Pasqualino Caccavelli
1997-04-25 4:00 ` Stephen Stuart
3 siblings, 0 replies; 5+ messages in thread
From: Finnbarr P. Murphy @ 1997-04-25 4:00 UTC (permalink / raw)
MAHENDRA@Meena.CC.URegina.CA (A. Mahendra Rajah) wrote:
> I am new to Unix and would like to ask 2 questions:
>
> 1) Is there any good book that will teach me shell programming
> using the Korn shell?
One good book is:
The Kornshell Command and Programming Language by Bolsky and Korn
- Published by Prentice Hall. ISBN 0-13-516972-0>
> 2) How do I debug this awk problem?
>
> $ x = "this+is+a+line+with+equals"
>
> I am trying to replace all the + characters with spaces.
>
> $ print $x | awk '{ i=gsub("+","",$0) }'
> "@awk: There is a regular expression error.
> *?+ not preceded by valid expression
> The source line number is 1.
> The error context is
> { i=gsub("+","",$0) >>> <<<
>
Try the following:
print $y | awk '{ gsub("\\+"," "); print }'
- Finnbarr -
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Korn shell programming - awk in particular
1997-04-24 4:00 Korn shell programming - awk in particular A. Mahendra Rajah
1997-04-25 4:00 ` Bob Vickers
1997-04-25 4:00 ` Finnbarr P. Murphy
@ 1997-04-25 4:00 ` Pasqualino Caccavelli
1997-04-25 4:00 ` Stephen Stuart
3 siblings, 0 replies; 5+ messages in thread
From: Pasqualino Caccavelli @ 1997-04-25 4:00 UTC (permalink / raw)
In article <5jodsm$df4$1@sue.cc.uregina.ca>,
MAHENDRA@Meena.CC.URegina.CA (A. Mahendra Rajah) wrote:
>
>
> I am new to Unix and would like to ask 2 questions:
>
> 1) Is there any good book that will teach me shell programming
> using the Korn shell?
>
> 2) How do I debug this awk problem?
>
> $ x = "this+is+a+line+with+equals"
>
> I am trying to replace all the + characters with spaces.
>
> $ print $x | awk '{ i=gsub("+","",$0) }'
> "@awk: There is a regular expression error.
> *?+ not preceded by valid expression
> The source line number is 1.
> The error context is
> { i=gsub("+","",$0) >>> <<<
>
> Any help will be greatly appreciated.
>
> Thanks,
>
>-----------------------
> mahendra (A. Mahendra Rajah :: Mahendra @ Meena.CC.URegina.CA)
> Systems Manager & Postmaster,
> Dept of Computing Services,
> University of Regina,
> Regina, Sask., Canada.
>-----------------------
>
Mahendra,
Can't help you with Q1 but as for Q2 maybe you can simplify the process by
using sed?
$x = "this+is+a+line+with+equals"
i=`echo $x | sed 's/^+/ /'`
Hope this helps.
Lino...
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Korn shell programming - awk in particular
1997-04-24 4:00 Korn shell programming - awk in particular A. Mahendra Rajah
` (2 preceding siblings ...)
1997-04-25 4:00 ` Pasqualino Caccavelli
@ 1997-04-25 4:00 ` Stephen Stuart
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Stuart @ 1997-04-25 4:00 UTC (permalink / raw)
: 1) Is there any good book that will teach me shell programming
: using the Korn shell?
http://www.amazon.com/
Do a subject search on "korn shell programming".
: 2) How do I debug this awk problem?
: $ x = "this+is+a+line+with+equals"
:
: I am trying to replace all the + characters with spaces.
: $ print $x | awk '{ i=gsub("+","",$0) }'
: "@awk: There is a regular expression error.
: *?+ not preceded by valid expression
: The source line number is 1.
: The error context is
: { i=gsub("+","",$0) >>> <<<
"+" is a special character in regular expressions. You need to quote
it to have it treated literally:
print $x | awk '{ i=gsub("\\+"," ",$0) }'
or
print $x | awk '{ i=gsub("[+]"," ",$0) }'
Stephen
- -----
Stephen Stuart stuart@pa.dec.com
Network Systems Laboratory
Digital Equipment Corporation
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1997-04-25 4:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-04-24 4:00 Korn shell programming - awk in particular A. Mahendra Rajah
1997-04-25 4:00 ` Bob Vickers
1997-04-25 4:00 ` Finnbarr P. Murphy
1997-04-25 4:00 ` Pasqualino Caccavelli
1997-04-25 4:00 ` Stephen Stuart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox