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?
I can think of two obvious ways. If you’ll have access to the
trutility (standard on any UNIX/Posix host) then you couldtr ',' '\n' < "$your_data_file" | while read each; do $process $each; doneIf 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
$eachwhich you might want to filter out separately.