11-30-2006
if within nawk command
I am trying to nawk through a file and if the 24.25.26 charachters in the file are "000" then print a line to a new file in one format, otherwise print a line in a different format.
So far I have the following:
nawk '/^1/ {
if(substr($0,24,3) != 000) printf("%.5d%s\n",NR-1,"0"substr($0,14,13)"XXX"substr($0,2,6)substr($0,32,7)"+"" XXXXXXXX""XXXX "" ""N")
else printf("%.5d%s\n",NR-1,"0"substr($0,14,10)"801""XXXX"substr($0,2,6)substr($0,32,7)"+"" XXXXXXXX""XXXX "" ""N")
fi
}' filename >> newfile
however this is reulting in a syntax error as follows, due to the if statement:
nawk: syntax error at source line 1
context is
/^1/ {if(substr($0,24,3) != 000) printf("%.5d%s\n",NR-1,"0"substr($0,14,
13)"XXXX"substr($0,2,6)substr($0,32,7)"+"" XXXXXXXX""XXXX ""
""N") >>> else <<< printf("%.5d%s\n",NR-1,"0"substr($0,14,10)"801""XXXX"su
bstr($0,2,6)substr($0,32,7)"+"" XXXXXXXX""XXXX "" ""N") f
i}
nawk: illegal statement at source line 1
Can anyone confirm the correct syntax for an if/else statement within a nawk command.
Thanks.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I am using the following command.
nawk '$1==p{$2=sprintf("%09d",$2+1)};1' p=$JOB_NUM q=$LEN $VALUE_TABLE > ./TEMP_TABLE
As you can see the code above, I basically read a value from the table VALUE_TABLE and select a particular row based on searching the value JOB_NUM. Now Actually the... (2 Replies)
Discussion started by: Tux_Raju
2 Replies
2. Shell Programming and Scripting
Guys, i have an issue. I tried to ran a script and the whole thing was fine.. except when i came to a part,
nawk '
BEGIN {
machine=0
then system prompted that the nawk command was not to be found...
I tried looking for the nawk command by using the "locate" command, and it returns... (5 Replies)
Discussion started by: 12yearold
5 Replies
3. Shell Programming and Scripting
Hello
I have facing issue while using cp command inside nawk block.
#!/bin/ksh
my_name=$1
nawk -v my_name1=$my_name 'BEGIN {
n = split(my_name1,names,":");
for (i=1;i<=n;i++)
{
print names;
cpcmd = "cp " /tmp/test.txt" " ./sample
system(cpcmd)
}
exit
}'
exit 0
i'am getting... (1 Reply)
Discussion started by: piscean_n
1 Replies
4. Shell Programming and Scripting
what is this nawk doing?
This is for solaris 10 with trusted extensions.
Level=$(plabel | nawk 'BEGIN {FS='\*"} {PRINT $2}' )
it is supposed to return UNCLASSIFIED or whatever the zone label is.
I understant $() execute this stuff, FS is field separator, print the 2nd field.
Can... (1 Reply)
Discussion started by: djehres
1 Replies
5. Shell Programming and Scripting
I have a nawk command I use in Solaris....
ps -e -o comm | nawk -F'ora_pmon_' 'NF>1 {print $2}'
However it seems that this command will not work in Linux.
Linux bluemarron 2.6.16.54-0.2.12-smp #1 SMP Fri Oct 24 02:16:38 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux
How could I do the same... (2 Replies)
Discussion started by: LRoberts
2 Replies
6. Shell Programming and Scripting
i am matching two files.
the files are in the format
file_1.txt
1|_|X|_|
2|_|W|_|
3|_|Y|_|
4|_|Z|_|
5|_|U|_|
file_2.txt
W|_|A|_|
Z|_|C|_|
V|_|B|_|
X|_|D|_|sdff|_|
Y|_|
file_3.txt should be in the format (4 Replies)
Discussion started by: centurion_13
4 Replies
7. Shell Programming and Scripting
Hi,
I am using NAWK command to scan a file (test.txt) and to create new files based on the length of lines in the file test.txt.
My requirement is I need to create test_good with records having line lenght less than 4
and to create test_bad with records having line lenght more than 4. I... (4 Replies)
Discussion started by: sbhuvana20
4 Replies
8. Shell Programming and Scripting
Hi All
We are migrating our projects from unix environment to linux. I tried running a install script which sets up my project, i.e. the directory structure and all. But in the middle of the script i started receiveing following error : nawk: command not found .
So i need to know which... (1 Reply)
Discussion started by: vee_789
1 Replies
9. Shell Programming and Scripting
Hi
I have this command, which counts number of lines in a specific file and then prints it on screen.nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename
I would like to have the output put into a variable, but can't seem to find the correct argument for it.
How do I... (3 Replies)
Discussion started by: bulleteyedk
3 Replies
10. UNIX for Beginners Questions & Answers
Hi Folks,
I am struggling to understand nawk command which was used by another developer.
Can you please explain what each character or string is doing here below:
if ; then (3 Replies)
Discussion started by: kirans.229
3 Replies
PERLKO(1) Perl Programmers Reference Guide PERLKO(1)
NAME
perlko - PerlX XXX XXX
DESCRIPTION
PerlX XXX XX XX XXXXX !
PerlX 5.8.0XXX XXXX/ISO 10646X XX XXXX XXX XXX. XXXX XXX XXXX XXXX XXX XX XXXX XXXX XXX XX XXX XXX XX XXX XX XXX XXXX XXXXX. XXXXX X XXXX
XXX XX XXX XX XX XX - XXX XX XXX, XX XXX, XXX XXX, XXX XX XXXX XXX XX XXXX, XX XX, XXX XX, XXXX XX, XXXX XX, XXXX XX, XX XXXX XX XX X-X
XXXX XX XXX XX XX XXX XXX XXX X XX X XX XXX XX XXX XXX XX XXX XXXX X X XX XX XXX XXXX XX XX XXXX XXXX XX XX XX XX XXX XXXX XXXX.
PerlX XXXXX XXXXX XX XXX XX XXXXX. XX XXXXX XXX Perl XXXX XXX UTF-8 XXXX X X XX, XX XXX XXX(XX XX, XXX, index, substr)X XXX XX XX XXXX XX
XXX XXXXX. (X XXX XX perlunicode XXXX XXXXXX.) XXXXX XX XXXX XX XX XXX XXX, XXX XX XXX XX XX/X XXX XXXXX XXXX XX XX XXXXX X XXXX XXX XXX XX
XX XX 'Encode'X XXXXX. XXXX 'Encode'X XX XXX XXX XXX XXX XX X X XXXX.
'Encode'X XXX XX XXX XXXX XXXXX.
euc-kr
US-ASCIIX KS X 1001X XX XX XXXXX XXX (XX XXXXXX
XX.) KS X 2901X RFC 1557 XX.
cp949
MS-Windows 9x/MEXX XXX XX XXX. euc-krX 8,822XX
XX XXX XX XX. aliasX uhc, windows-949, x-windows-949,
ks_c_5601-1987. X XXX XXX XXXX XX XXXXX, Microsoft
XXXX CP949X XXX XXX XX.
johab
KS X 1001:1998 XX 3XX XXX XXX. XX XXXXX cp949X
XXXXX US-ASCIIX KS X 1001X 8,822XX XX XXX XX XX.
XXX XXX XX XX.
iso-2022-kr
RFC 1557XX XXX XXX XXX XX XXX XXXXX US-ASCIIX
KS X 1001X XXXXX XX XXX euc-krX XXX XXX XXX XX.
1997-8X XXX XXXX X XX XX XXX XXX XX.
ksc5601-raw
KS X 1001(KS C 5601)X GL(X, MSBX 0XX X XX) X XXX XX
XXX. US-ASCIIX XXXX XX XXXX XXX XX X11 XXX XX
XXX (ksc5601.1987-0. '0'X GLX XXX.)XX XXX XX XXXXX
XX XX. KS C 5601X 1997X KS X 1001X XXX XXXX. 1998XXX X
XX (XXX XXX XX XX XX)X XXXX.
X XX XX XXX XXX XXXX.
XX XX, euc-kr XXXXX X XXX UTF-8X XXXXX XXX XX XX XXX.
perl -Mencoding=euc-kr,STDOUT,utf8 -pe1 < file.euckr > file.utf8
XXXX XXX XX X X XXXX.
perl -Mencoding=utf8,STDOUT,euc-kr -pe1 < file.utf8 > file.euckr
XX XXX XX XXXX X X XXX Encode XXX XX
XXXX PerlXX XX piconvX PerlX XX XXXX.
X XXXX X X XXX piconvX UnixX XX iconvX
XXX X XXXX. X XXXX XXX XXXX.
piconv -f euc-kr -t utf8 < file.euckr > file.utf8
piconv -f utf8 -t euc-kr < file.utf8 > file.euckr
X, 'PerlIO::encoding' XXX XX XXX XXXX XXX XX XX
(XXX XXX XXX) XXX XX X X XXXX.
#!/path/to/perl
use encoding 'euc-kr', STDIN => 'euc-kr',
STDOUT-> 'euc-kr', STDERR=>'euc-kr';
print length("XX"); # 2 (X XXXX XX XX XXX XX)
print length('XX'); # 4 (XX XXXX XXX XX XXX XX)
print index("XX, XXX", "X"); # -1 ('X'X XX)
print index('XX, XXX', 'X'); # 7 (8XXX 9XX XXXX 'X'X
XXXX XXX.)
X XXX XX XXX...
PerlX XXXX XXX XXX XXX XX XX XX, X XXX XX
Perl XX X XXX XXXX XX, EncodeX XXX XX XX XX
XX X XXXX. XX X XXX XX XX XXX XX XXXX.
Perl XX XX
XXX XXX XX XXX XXX XX XXX XXXX. X XXX XX XXX XX XXX XX XXXX XX XX XXXX.
<http://www.perl.com/>
O'ReillyX Perl X XXX
<http://www.cpan.org/>
Comprehensive Perl Archive Network
<http://lists.perl.org/>
Perl XXX XXX. XX XXX XXX
perl-unicodeXX 'Encode'X XX XXX.
PerlX X XX XXXXX XXX X X XX XXX XX XXX
<http://www.perl.or.kr/>
Perl XX XXX XX
<news:han.comp.lang.perl/>
XXX Perl XX XX
<http://www.hanb.co.kr/search/searchResult.html?keyword=perl>
O'ReillyXX XX XXX Perl XX XX
<http://www.perlschool.net/>
Perl XX XX X XX, XX XX, XX XX XXX XX
<http://www.perl.co.kr>
PerlX XXX CGI, DB, XX XX XX XX X XX XX
XXXX X XXX XXX XX XX
<http://www.unicode.org/>
XXXX XXXX.
<http://std.dkuug.dk/JTC1/SC2/WG2>
XXXXX UnicodeX XX ISO XXX ISO/IEC 10646 UCS(Universal Character Set)X XXX ISO/IEC JTC1/SC2/WG2X X XXX.
<http://www.cl.cam.ac.uk/~mgk25/unicode.html>
XXX/XXXXX XXXXX UTF-8 XXX XX XXX(FAQ)
http://wiki.kldp.org/Translations/html/UTF8-Unicode-KLDP/UTF8-Unicode-KLDP.html <http://wiki.kldp.org/Translations/html/UTF8-Unicode-
KLDP/UTF8-Unicode-KLDP.html>
XXX/XXXXX XXXXX UTF-8 XXX XX XXX(FAQ)X XXX XX
SEE ALSO
Encode, Encode::KR, encoding, perluniintro, perlunicode
AUTHORS
Jarkko Hietaniemi <jhi@iki.fi> XXX <jshin@mailaps.org>
perl v5.16.2 2012-10-11 PERLKO(1)