If you do need a shell loop to process that, you could use read
's IFS
-spliting to split on |
s instead of using awk
:
#! /bin/bash -
shopt -s extglob
trim() {
typeset -n _var
for _var do
_var=${_var##+([[:space:]])}
_var=${_var%%+([[:space:]])}
done
}
{
IFS= read -ru3 header_discarded
while IFS='|' read -ru3 rev svn_path file download_options rest_if_any_ignored; do
trim rev svn_path file download_options
# do what you need with those variables
typeset -p rev svn_path file download_options
done
} 3< input_file.txt
Here, on your sample, that gives:
declare -- rev="1336"
declare -- svn_path="svn/Repo/PROD"
declare -- file="test2.txt"
declare -- download_options="PROGRAM APPLICATION_SHORT_NAME=\"SQLGL\""
declare -- rev="1334"
declare -- svn_path="svn/Repo/PROD"
declare -- file="test.txt"
declare -- download_options="REQUEST_GROUP REQUEST_GROUP_NAME=\"Program Request Group\" APPLICATION_SHORT_NAME=\"SQLGL\""