Using pipe command between process and concatenate

Dear all,

I use a pipe command to assign a variable:

[x004191a@xsnl11p317a tmp]$ v_LstStdCdhId=$(cat Bteq_Xport_GetLstStdViewToBuild__1274.txt | grep 'CD/39/AT/CDH_BV_ODS'|cut -d"/" -f1)
[x004191a@xsnl11p317a tmp]$ echo "${v_LstStdCdhId}"
43
49

My aim is to concatenate for each line of the variable v_LstStdCdhId the character "/" in order to obtain:

[x004191a@xsnl11p317a tmp]$ echo "${v_LstStdCdhId}"
43/
49/

Is it possible to get that result directly, using korn-shell syntax, in the assignment command ?

Thanks a lot,

Try

VAR=$(awk -F"/" '/CD\/39\/AT\/CDH_BV_ODS/ {print $1 FS}' Bteq_Xport_GetLstStdViewToBuild__1274.txt)

Can't be tested as the input file has not been posted.

1 Like

If you want to assign it all to one variable and then use that value in a loop?
Try:

while IFS=/ read v_LstStdCdhId rest
do
  if [[ $rest == *CD/39/AT/CDH_BV_ODS* ]]; then
    echo "${v_LstStdCdhId}/"
  fi
done < Bteq_Xport_GetLstStdViewToBuild__1274.txt

If you want to assign it all to one variable try:

v_LstStdCdhId=$(
  while IFS=/ read f1 rest
  do
    if [[ $rest == *CD/39/AT/CDH_BV_ODS* ]]; then
      echo "${f1}/"
    fi
  done < Bteq_Xport_GetLstStdViewToBuild__1274.txt
)
1 Like

Many thanks to each of you, Rudi & Scrutinizer ... your proposals helped me a lot,