0

I have a file which contains values like:

CA, PA, NY
ND, MO, MI

I need to process these values one by one. The flowchart will be as follows:

Enter loop -> Process CA; Process PA; Process NY -> Other commands -> Process ND; Process MO; Process MI -> End;

Is this possible using shell scripting?

1 Answer 1

2

I can think of two obvious ways. If you'll have access to the tr utility (standard on any UNIX/Posix host) then you could tr ',' '\n' < "$your_data_file" | while read each; do $process $each; done If not then you could probably still use the shell's IFS (inter-field separator) using something like: cat "$your_data_file"| { IFS=','; while read line; do for each in $line; do echo $each; done; done; } (Note you can use {} grouping or () for a subshell ... they are effectively the same in this example).

Note you might have some extraneous whitespace in $each which you might want to filter out separately.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.