0

I'm trying the code below attempting to print "$2" "$5-*")

while IFS= read -r a name x x desc; do
   printf '%-15s %s\n' "$name" "$desc"
done < <(grep "^function" ~/.functions)

but it seems that the entire line is being assigned to $a

What am I doing wrong? Running grep (GNU grep) 3.7

Thanks

rr0ss0rr
  • 332
  • 2
  • 6
  • 2
    What are you expecting `IFS=` to do? What separates the fields of your `grep` output? – steeldriver Mar 11 '22 at 01:45
  • separated by spaces – rr0ss0rr Mar 11 '22 at 02:09
  • 1
    See [Why is using a shell loop to process text considered bad practice?](https://unix.stackexchange.com/q/169716). Use awk or perl or some other language. e.g. `awk '/^function/ { printf "%15s", $2; $1=$2=$3=$4=""; $0=$0; print $0 }' ~/.functions`. or `perl -lane 'if (/^function/) { printf "%15s %s\n", $F[1], join(" ", @F[4..$#F]) }' ~/.functions` – cas Mar 11 '22 at 05:36
  • cas, Thanks .. I tried awk but couldn't get it to print correctly. Please post this as the answer. Thanks again – rr0ss0rr Mar 11 '22 at 11:20

0 Answers0