Link to home
Start Free TrialLog in
Avatar of Melodi Roberts
Melodi RobertsFlag for United States of America

asked on

LINUX Field Separators

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
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Melodi Roberts
Melodi Roberts

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.
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?
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}'`
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.
Avatar of Melodi Roberts

ASKER

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.
Thanks. Your feedback helped move me in the right direction with checking the FS command.