LINUX Field Separators

Melodi Roberts
Melodi Roberts used Ask the Experts™
on
We have a de-supported baseline shell script that runs jobs for Appworx.  After migrating from UNIX to LINUX, it no longer works to accept multiple values for a job parameter.  Attached is the code.  I do not know shell scripting, but am attempting to learn....  I was able to get something to work with field separators at the command line but have not yet gotten changes to work with the full script.

Does anyone know all that needs to be changed to get the field separation to work on LINUX?
BANJSUBP2_ONE
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
The script includes events that could help identify the break point.
It also includes an option Near the top of the script to enable debugging.
The print to screen could point where the issue i.e. An expected condition was not met leading to the termination of the script.
It is impossible for someone who has no access to the data to determine an issue from a script.
I'd actually turned on the debugging to see that the piece of code that seems that it should be breaking apart a string using separator values was not working.  There is no fatal error occurring.  e.g. A parameter string might be ML~PM with '~' being the separator value.  The job being executed is only receiving the first value and not the second where more than one value is allowed and passed with the ~ separator.  I was hoping that someone could spot some code that perhaps works on UNIX but not LINUX as was the case for some of our other shell scripts that we migrated to LINUX, but it sounds like this is not the case. Thank you for your feedback.
Distinguished Expert 2017

Commented:
This script seems to be called from another where some variables program, command, etc have to be set.
You have to make sure the same tools, awk, etc. are available and are within path.

You have to make sure that the same components that are available on UNIX are available/installed and since you use relative references that the commands are in the PATH

Do you have an example on what this script being called with?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I do not have the example.  I am asking for access to more of the underlying code now, but I think I found a solution.

I played around with the line of code below because I could see it was not breaking apart the line based on the tilde/'~' character.

       var=`echo $line|awk '{{ FS = "~"}{ print $1}}'`

I changed it to what you see below  and although I need to do more testing, this appears to have done the trick.

     var=`echo $line | awk -F~ '{print$1}'`
Distinguished Expert 2017

Commented:
do you have two separate accounts, you might want to check and have them consolidated into one.


In order to fix, it has to be identified what is broken or where or under what circumstance the data stream strays from the expected.
Melodi RobertsProgrammer/Analyst

Author

Commented:
I thought I already pointed that out.  The issue is with the command below.
var=`echo $line|awk '{{ FS = "~"}{ print $1}}'`

It should take a line value of 1ML~2PM and print 1ML. It prints 1ML~2PM. I used an echo command to check on it.

When I changed the command to the command below it now works.
var=`echo $line | awk -F~ '{print$1}'`

Perhaps LINUX and our full set up with it does not support the FS command or something.

I will close out this issue and check on my EE accounts.  Thanks.
Melodi RobertsProgrammer/Analyst

Author

Commented:
Thanks. Your feedback helped move me in the right direction with checking the FS command.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial