We help IT Professionals succeed at work.

LINUX Field Separators

Last Modified: 2017-03-14
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?
Watch Question

Distinguished Expert 2019
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
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 2019

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}'`
Distinguished Expert 2019

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


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


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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions