I have below two variables: $var1 which has value like
ABC
XYZ
SDF
and $var 2 which has value like
SDF
SGDGH
hfg
I want the output like
ABC
XYZ
SDF
SDF
SGDGH
hfg
I have the below script and i want to merger the value of file_import_2 and file_import_3 into one.
file_import_2=""
file_import_3=""
for DataBase in $(< "$1"); do
file_import_1=`grep -iw "CRQ_DI_PROD_$DataBase" "$Import_List_File" | grep -i prod`;
if [[ "$file_import_1" = GDH_* ]]; then
file_import_2=$file_import_1
fi
if [[ "$file_import_1" != GDH_* ]]; then
file_import_3=$DataBase
fi
var3=$(printf '%s\n%s\n' "$file_import_2" "$file_import_3")
echo $var3
done
The file i am passing to the script and Import_List_File have 4 values each
FARP_DATA_111
TRIN_STAGING
DBH
PRS
With the print f solution, output is:
CRQ_DI_PROD_FARP_DATA_111
CRQ_DI_PROD_TRIN_STAGING
CRQ_DI_PROD_TRIN_STAGING DBH
CRQ_DI_PROD_TRIN_STAGING PRS
printf "%s\n" "$var1" "$var2"
? – cas Aug 30 '19 at 10:23file_import_2="$file_import_1"
andfile_import_3="$DataBase"
. Ditto for command substitution, e.g.var3="$(printf '%s\n' "$file_import_2" "$file_import_3")"
. See Why does my shell script choke on whitespace or other special characters? – cas Aug 30 '19 at 10:42foo="$bar"
. If there's any chance that the right-hand-side of an assignment might contain whitespace or shell meta-characters (like&
) then you need to quote the RHS, with either single-quotes (for literal, fixed, static text) or double-quotes (if you want variable expansion, command substitution, etc to happen). – cas Aug 30 '19 at 11:38