Awk Help Please 
Author Message
 Awk Help Please


% read sortfile
% if [ ! -f $chasdir/$sortfile ]; then
%  echo File does NOT exist...
%  exit 1
% fi

Here's a problem, you want $sortfile to be in $chasdir, but what you
pass to awk is

% awk $sortfile '/

$sortfile without $/chasdir. Apart from that, you've got the awk program
and the awk script in the wrong order. Try
 awk '/01(BIR|TAPR|TBOT|TCAP|TCLE|TCON|TEAR|TFLS|TLAN|TMOW|TPAD|TPLU|TRUR|TTIL)/ {
      sub(" 01"," 02"); sub("^A","D") } { print }' $chasdir/$sortfile

You've got one more problem here. Your input records are delimited by
carriage-returns, but the default record separator in awk is new-line.
You need to change the RS variable to reflect this:

 awk 'BEGIN { RS = "\r" }
      /01(BIR|TAPR|TBOT|TCAP|TCLE|TCON|TEAR|TFLS|TLAN|TMOW|TPAD|TPLU|TRUR|TTIL)/ {
      sub(" 01"," 02"); sub("^A","D") } { print }' $chasdir/$sortfile

--

Patrick TJ McPhee
East York  Canada



Fri, 02 Jan 2004 22:17:48 GMT  
 Awk Help Please


Quote:


>% read sortfile
>% if [ ! -f $chasdir/$sortfile ]; then
>%  echo File does NOT exist...
>%  exit 1
>% fi

>Here's a problem, you want $sortfile to be in $chasdir, but what you
>pass to awk is

>% awk $sortfile '/

>$sortfile without $/chasdir. Apart from that, you've got the awk program
>and the awk script in the wrong order. Try
> awk '/01(BIR|TAPR|TBOT|TCAP|TCLE|TCON|TEAR|TFLS|TLAN|TMOW|TPAD|TPLU|TRUR|TTIL)/
>{
>      sub(" 01"," 02"); sub("^A","D") } { print }' $chasdir/$sortfile

>You've got one more problem here. Your input records are delimited by
>carriage-returns, but the default record separator in awk is new-line.
>You need to change the RS variable to reflect this:

> awk 'BEGIN { RS = "\r" }
>      /01(BIR|TAPR|TBOT|TCAP|TCLE|TCON|TEAR|TFLS|TLAN|TMOW|TPAD|TPLU|TRUR|TTIL)/
>{
>      sub(" 01"," 02"); sub("^A","D") } { print }' $chasdir/$sortfile

>--

>Patrick TJ McPhee
>East York  Canada


Nit-picking detail:-

sub(/regular expression/,"replacement string")

is generally better than

sub("regular expression","replacement string")

because this avoids the complication of escaping any special characters
in the regular expression.

You might use a variable to contain a dynamic regular expression as a
string but I see no advantage in using a literal string containing a
regular expression.

--
Alan Linton



Sat, 03 Jan 2004 04:34:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Arrays in awk/awk help please!

2. Tracing awk - help, please

3. Need awk (or sed) help PLEASE!

4. Bit of awk help needed, please

5. date variable in awk? please help

6. help with awk/sed, please

7. awk /start/,/stop/ Please HELP

8. awk:Simpler question: But critical ; please help

9. please help, AWK and Shell ?

10. AWK Portability (please help)

11. AWK gurus please help

12. Please help, awk question!

 

 
Powered by phpBB® Forum Software