i am trying to reflect the name (example: LDRIVE in to RDRIVE) in UNIX
sun environment and please find below the script i used.
awk -F ">" '{if (substr($2,2,1) != " ") if ((match(substr($2,2,1),
"[RL]") != 1) and !((match(substr($2,2,1), "[FCA]") == 1) and
(match(substr($2,3,1), "[RL]") == 1))) printf "(VNAME 1 %d, %6d ) =
%s (unchanged)\n", length(substr($2,2)), NR, substr($2,2); else if
(substr($2,2,1) == "R") printf "(VNAME 1 %d, %6d ) = L%s (was %s)\n",
length(substr($2,2)), NR, substr($2,3), substr($2,2); else if
(substr($2,2,1) == "L") printf "(VNAME 1 %d, %6d ) = R%s (was %s)\n",
length(substr($2,2)), NR, substr($2,3), substr($2,2); else if
( match(substr($2,2,1), "[FfCcAa]") == 1 ) if (substr($2,3,1) == "R")
printf "(VNAME 1 %d, %6d ) = %sL%s (was %s)\n", length(substr($2,2)),
NR, substr($2,2,1), substr($2,4), substr($2,2); else if
(substr($2,3,1) == "L") printf "(VNAME 1 %d, %6d ) = %sR%s (was %s)
\n", length(substr($2,2)), NR, substr($2,2,1), substr($2,4),
substr($2,2)}' gridnames
awk -F ">" '{if (substr($2,2,1) != " ") if ((match(substr($2,2,1),
"[RL]") != 1) and !((match(substr($2,2,1), "[FCA]") == 1) and
(match(substr($2,3,1), "[RL]") == 1))) printf "(VNAME 1 %d, %6d ) = %s
\n", length(substr($2,2)), NR, substr($2,2); else if (substr($2,2,1)
== "R") printf "(VNAME 1 %d, %6d ) = L%s\n", length(substr($2,2)), NR,
substr($2,3); else if (substr($2,2,1) == "L") printf "(VNAME 1 %d,
%6d ) = R%s\n", length(substr($2,2)), NR, substr($2,3); else if
( match(substr($2,2,1), "[FfCcAa]") == 1 ) if (substr($2,3,1) == "R")
printf "(VNAME 1 %d, %6d ) = %sL%s\n", length(substr($2,2)), NR,
substr($2,2,1), substr($2,4); else if (substr($2,3,1) == "L") printf
"(VNAME 1 %d, %6d ) = %sR%s\n", length(substr($2,2)), NR,
substr($2,2,1), substr($2,4)}' gridnames >> piok.in2
the following error is coming when i execute:
awk: syntax error near line 1
awk: bailing out near line 1
awk: syntax error near line 1
awk: bailing out near line 1
can any one help in shorting out
thanks
ravi
Just a note...
It is possible to put awk programs in a file, say "trash.awk", and
call it as...
awk -f trash.awk datafiles
Then you can also format your code (for free; no extra fee) to become
readable by using a single command per line and proper indentation.
Doing that will greatly increase the number of people who are willing
to analyse your code. Having an awk program of many lines might also
point you to the line number of your problem without necessity to ask
here.
Are you working on solaris? Try /usr/xpg4/bin/awk instead of /bin/awk.
Janis
>
> thanks
>
> ravi
>hi,
>
>i am trying to reflect the name (example: LDRIVE in to RDRIVE) in UNIX
>sun environment and please find below the script i used.
>
>awk -F ">" '{if (substr($2,2,1) != " ") if ((match(substr($2,2,1),
>"[RL]") != 1) and !((match(substr($2,2,1), "[FCA]") == 1) and
>(match(substr($2,3,1), "[RL]") == 1))) printf "(VNAME 1 %d, %6d ) =
>%s (unchanged)\n", length(substr($2,2)), NR, substr($2,2); else if
>(substr($2,2,1) == "R") printf "(VNAME 1 %d, %6d ) = L%s (was %s)\n",
>length(substr($2,2)), NR, substr($2,3), substr($2,2); else if
>(substr($2,2,1) == "L") printf "(VNAME 1 %d, %6d ) = R%s (was %s)\n",
What ever happened to whitespace and structure?
Grant.
--
http://bugsplatter.id.au/
Try nawk or /usr/xpg4/bin/awk rather than /bin/awk.
At least you'll get a better error message.
--
echo imhcea\.lophc.tcs.hmo |
sed 's2\(....\)\(.\{5\}\)2\2\122;s1\(.\)\(.\)1\2\11g;1s;\.;::;2'
Hi,
In addition to Janis'recommendations, you'd gain in readability if you
were storing function results into intermediary variables.
Anyway, I think the errors arise from the fact that "and" is not the
right logical conjunction operator. You'd rather use "&&".
Hope it helps.
Cheers,
Jean-Philippe
Greetings and thanks for your effort.
when i execute the above script in hp workstation it is working fine
but in the sun machine it is not working. can you guide me to short
out from the below error:
awk: syntax error near line 1
awk: bailing out near line 1
awk: syntax error near line 1
awk: bailing out near line 1
thanks
ravi
As said, instead of...
awk -F ">" '...'
try
/usr/xpg4/bin/awk -F ">" '...'
or reformat your code to make it legible for an analysis.
Janis
> Greetings and thanks for your effort.
>
> when i execute the above script in hp workstation it is working fine
> but in the sun machine it is not working. can you guide me to short
> out from the below error:
>
> awk: syntax error near line 1
> awk: bailing out near line 1
> awk: syntax error near line 1
> awk: bailing out near line 1
Don't use awk. Use nawk. This is new awk.
Both ar on the SOlaris OS.
There are many many reasons to use the new awk.
Reason #1 - better error messages.
Or /usr/xpg4/bin/awk. Just don't use old, broken awk.
> Both ar on the SOlaris OS.
> There are many many reasons to use the new awk.
> Reason #1 - better error messages.
Reason #1 - fewer error messages ;-).
Ed.
Why do people give this crappy advice? Both nawk and xpg4awk are just
somewhat better (read: not terrible) than Solaris:binawk.
If you're going to go non-standard (don't bother to argue with this; you
know what I mean), just get GAWK and be happy.
>> Both ar on the SOlaris OS.
>> There are many many reasons to use the new awk.
>> Reason #1 - better error messages.
>
>Reason #1 - fewer error messages ;-).
>
> Ed.
Yes. That should be:
Reason #1 - fewer error messages
Reason #2 - better error messages
No, there's a significant difference in usability between old, broken awk and
any modern awk (/usr/xpg4/bin/awk, nawk, gawk, etc.). All the modern awks are
usable, there's just relatively small differences in functionality between them
with gawk having the most extensions.
>
> If you're going to go non-standard (don't bother to argue with this; you
> know what I mean), just get GAWK and be happy.
I agree everyone should use gawk if possible but you can get by with any other
modern awk, it'll just be a little harder to get some jobs done.
Ed.
Your reply brings haunting memories from my past. In a
situation where I had the root password and "full" control
over a system, your advice to "get gawk" is good. However,
the real world of a policy and moreso, a politicer in the
admin group over the systems, getting anything is not an
option.
I took the reply to say, "using what is available on the
system as it has been configured by those in power ..."
Old Man
Hi Old Man, it's time to upgrade to New Man.
Reason #1 - fewer fatalistic messages
nawk and /usr/xpg4/bin/awk implement the Awk Programming Language,
as defined in the book of that name. It is a vast improvement over
the old (i.e., pre-1988) awk.
Gawk offers a few unimportant extensions, most of which are rarely
necessary.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Very funny. Proves the art of satire is not dead.
Good show.
[...]
> >>> Don't use awk. Use nawk. This is new awk.
> >>Or /usr/xpg4/bin/awk. Just don't use old, broken awk.
> > Why do people give this crappy advice? Both nawk and
> > xpg4awk are just somewhat better (read: not terrible) than
> > Solaris:binawk.
> nawk and /usr/xpg4/bin/awk implement the Awk Programming Language,
> as defined in the book of that name. It is a vast improvement over
> the old (i.e., pre-1988) awk.
I've had at least one case where /usr/xpg4/bin/awk accepted my
code, but nawk didn't.
In general, if you're working under Solaris, you should have
/usr/xpg4/bin in your path, before /usr/bin, so just awk will
get you the good one. (More generally, you should have:
` getconf PATH `
somewhere in your $PATH if you want a conformant environment.)
> Gawk offers a few unimportant extensions, most of which are rarely
> necessary.
And some of which introduce new keywords, which may break your
code. If all you've got is gawk, then you should invoke it as
"gawk --posix" (but in practice, this is only very occasionally
a problem).
--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34