awk treating variables differently in UNIX-Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk treating variables differently in UNIX-Linux
# 8  
Old 09-06-2016
Thank you Don Cragun for the ideas.

It is so, that unfortunately many of our Scripts in HP-UNIX had simply used the %s (for example %011s) in awk-printf statements (without having to check if the column values were integers or strings) . Now they need to be handled differently when migrating to Linux and calls for too much testing Smilie
# 9  
Old 09-06-2016
Linux:
Code:
$ /usr/bin/printf "%05s\n" 123
/usr/bin/printf: %05s: invalid conversion specification

---------- Post updated at 09:12 ---------- Previous update was at 08:11 ----------

Perhaps you can repair your shell scripts with the following:
Code:
perl -i.orig -pe 'while (s/(printf\s+(['\''][^'\'']*|["][^"]*)%)0(\d+s)/$1$3/){}' filename...

This User Gave Thanks to MadeInGermany For This Post:
# 10  
Old 10-04-2016
Thank you all. The scripts have been adjusted and tested and all is fine again. It made sense to assume that only a number would need to be filled with '0's in the beginning and we changed most %0<n>s to %0<n>d. Only in a couple of cases there was some alphabets involved. They had to be handled separately.

Thanks again for all responses.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AIX to RHEL migration - awk treating 0e[0-9]+ as 0 instead of string issue

Greetings Experts, We are migrating from AIX to RHEL Linux. I have created a script to verify and report the NULLs and SPACEs in the key columns and duplicates on key combination of "|" delimited set of big files. Following is the code that was successfully running in AIX. awk -F "|" 'BEGIN {... (5 Replies)
Discussion started by: chill3chee
5 Replies

2. Shell Programming and Scripting

Why awk perform differently when using variable?

Hi Gurus, I hit a hard block in my script. when using awk command with variable, I got different result. Please see below: my test file as below: $ cat demofile.txt filename-yyyy-abcd filename-xxx-week-pass filename-xxx-week-run for testing purpose, I put 3 awk command in one script.... (7 Replies)
Discussion started by: ken6503
7 Replies

3. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

4. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

awk - treating remaining columns as one

Hi all, For no particular reason, I would like to use awk on a file that contains multiple columns, but let's say only columns 1 and 2 have some text values, and the remainder of the line contains text that I would like to treat as one column, considering I have spaces as delimiter for the... (33 Replies)
Discussion started by: ppucci
33 Replies

6. UNIX for Advanced & Expert Users

Unix script rm behaiving differently in difference machine

Hi All The below is the script, if i supply the script with the argument -f then it will delete the tmp file . We are having 3 unix system out of that two system are processing this file only one system is not processing and the error showin is below the script .. can you please help me ... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

7. Windows & DOS: Issues & Discussions

Awk script in DOS and Linux behaves differently :(

Hi, I have an awk script which performs simple operations of variable assignments and finally printing the variables in custom form. BEGIN {FS=OFS="\n"} { v1=substr($0,1,15) v2=substr($0,16,200) v3=substr($0,216,20) print v1 "|" v2 "|" v3 } The input file being processed... (2 Replies)
Discussion started by: vidyak
2 Replies

8. Shell Programming and Scripting

simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator: #!/bin/csh set shz=2 set zshift=5 set shzp=`bc -l <<END \ scale = 3 \ -1. * $shz + $zshift \ END` echo $shzp The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8. ... (2 Replies)
Discussion started by: two reelers
2 Replies

9. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

10. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question