I have developed a bash shell script which works perfectly fine when any bash shell is in use except SunOS.
There are two commands that is not compatible.
#!/usr/bin/env bash
Problem
1. The awk command below does not work for SunOS
Requirement
We extract Oracle EBS tables into text files and there is need to calculate the Sum total from the following hashTables for the following hashTableFields.
So GL_BALANCES.txt will have a column PERIOD_NET_CR. We are summing it and storing the result into a Log File.
--------------------
Log file content with Hash total values generated. This is not happening currently in SunOS. For rest OS, it is working as expected
---------------------
2. Split command does not work in SunOS
Requirement
If number of records exceed 5000000, then
...
...
until all records are placed into multiple files. Each file cannot contain more than 5000000 records. After each file, the subsequent file will contain next set of records.
Please note - the above codes are working as expected in Linux and other OS except SunOS.
We are ready to write them differently based on SunOS compatibility.
Any help is appreciated
Last edited by joeyg; 04-19-2018 at 11:17 AM..
Reason: code tags bolded text removed; better title
As far as the awk part goes. I'd be tempted to have awk calculate the sum directly and get rid of the bc and round functions. How many decimal places of precision do you need in the final sum?
Something like this (4 digits of precision, change printf line for more/less):
Check you split(1) manual on sunos but I believe the issue is -d for numeric suffixes. You may have to forgo these in SunOS or rename the files after split has done it's bit.
Perhaps:
Last edited by Chubler_XL; 04-18-2018 at 10:53 PM..
Step 1: verify that the $awkcmd variable has the right data in it. i.e.,
should show nawk.
Then verify that nawk is in the PATH variable of the process running the code:
Do that before playing with the awk code itself.
The awk code is clunky but looks, eh.., reasonable maybe, for nawk. If you get no output then you must rule out or find an error message about nawk not found, or if $awkcmd is not assigned you will get a shell error because the shell will try to run the awk code which is gibberish to the shell.
You need to start looking from the very first line, IMO. Keep ruling out problems as you go forward. Do not simply jump ahead 30 lines.
Last edited by jim mcnamara; 04-19-2018 at 08:30 AM..
It's been awhile since I dealt with Solaris' nawk, but it did have its quirks..
I'd start with: "$awkcmd" -F"#|#"
What do you think your field separator is?
A string #|# ? Maybe or maybe not. It might be a regex: #OR#.
I'd debug this first with the debug printf for each field.
Or try "#[|]#" to force it into a string.
Also: if ( $p=="|" || $p=="#|" || $p=="#" || $p=="|#" ) doesn't make too much sense given your definition of of the field separator.
Hi,
Can someone please guide me how to combine the following two awk calls in one?
I noticed that it is very often situation for me, and I think that it can be replaced with one awk call.
The question is more general, not the exact one.
echo "A B C/D" | awk '{print $3}' | awk -F/ '{print... (4 Replies)
my code:
gawk 'NR>'"${LASTLINENUM}"' && NR<='"${LINEENDNUM}"'' ${LOGFILE} | gawk '{l=$0;} /'"${STRING1}"'/ && /'"${STRING2}"'/ {for (i=NR-'"${BEFOREGLAF}"'; i<=NR+'"${AFTERGLAF}"'; i++) o=i; t++;} END { for(i=1; i<=NR; i++) if (o) print l; print t+=0;}'
i would like to combine this into one... (5 Replies)
Hey guys i want to use shell commands like ls, find, cd and more with in awk statements with inputs from the awk variables.
Like in the below code how can i change the directory using the value of path. Please suggest
awk '{ while (i<NR)
{
i++;
percentage = $5;
path = $6;
... (2 Replies)
I want to create an awk script that performs different things on different files.
For example, for files with extension .ry I might do something, but for .xt I do something else, and another things on .zc files.
How can I do this in one awk script? (3 Replies)
Hi,
I've searched this site and the wider web and have not found anything (that I can understand..) that helps me.
I've used shell commands in awk fine in the past, the difference is that I want to pass the shell command a field variable within awk from the current input.
A simple example... (3 Replies)
Hi, I have 2 lists of words and I need to take every line in first_list.txt and use agrep command to find similar words in whole second_list.txt.
I tried to use AWK, but I dont know how to take current line ($0) and use in inside of agrep
cat first_list.txt | awk ''
Thanks for help (10 Replies)
Hi,
I have a scenario where in, I have a file named abc.txt.
I extract the file names from it using.
awk '/dbf$/{print $NF}' abc.txt
/u01/oradata/omc/systab/omcdef.dbf
/u01/oradata/omc/oratemp/temptab1.dbf
Now I need to further enhance this command and also extract the mount point... (3 Replies)