#! /bin/bash -
shopt -s extglob # for +(...) ksh-style glob operator
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;rest_if_any_discarded; 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
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\""
That input could also be seen as simple CSV with |
as field separator, so you could preprocess it with something like:
mlr --csvlite --fs '|' --ho --ragged clean-whitespace then \
cut -of 'REV NUM,FILE NAME,DOWNLOAD OPTIONS'
Which would take care of extracting the fields you want, however they're positioned in the input and do the whitespace trimming (and then pipe to IFS='|' read -r rev file download_options
)