1

Is there a way to make this script not require a loop, by re-piping the splitted current line to the next command ?

somefunction | while IFS='_' read -a ENTRY
do
  echo "${ENTRY[0]};${ENTRY[3]}"
done

It is possible to make a shorter version of it, example :

somefunction | IFS='_' read -a ENTRY | echo "${ENTRY[0]};${ENTRY[3]}"

Thanks

1 Answer 1

3

You can't pipe shell state (i.e. variables) like that, but if I understand what you're doing, you can use a more appropriate tool for the job:

somefunction | awk -F _ '{print $1 ";" $4}'
1
  • Good approach. One remark though: the OP didn't use read -r; if it's their informed decision then awk may not be more appropriate. Sep 17, 2019 at 7:12

You must log in to answer this question.