Timeline for Can I change FIELDWIDTHS for each line of an awk script?
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 24, 2021 at 15:00 | comment | added | Cbhihe | +1 I was just using the comma separation as an example, but I agree about the associative array being non-portable would be an issue. I really don't like the idea of hard coding something with external dependencies inside an awk script. Everything depends on use-case anyway and we're short on such info. | |
| Apr 24, 2021 at 13:33 | history | edited | Ed Morton | CC BY-SA 4.0 | added 539 characters in body |
| Apr 24, 2021 at 13:20 | comment | added | Ed Morton | @Cbhihe it's not clear why hard-coding the array in shell and passing it to awk would be better than just hard-coding the array in awk. You'd need more code than that to do what you suggest too as you'd need to split b by newlines (not commas) to get the fieldwidths strings for every type of input line, but then also pass the type string (e.g. "12") associated with the fieldwidths string as the mapping doesn't appear to be numerically incremental indices (e.g. it seems to be 2-digit strings). You could define an associative array in the shell as a step but that's non-portable as well as slow | |
| Apr 24, 2021 at 12:32 | comment | added | Cbhihe | Inefficiencies apart, rather than hard coding type2fw array in the BEGIN block it's perhaps more agile to pass a string var from shell to Awk as awk -v b=$(for i in "${type2fw[@]}"; do printf "%s","$i";done | cut -c 2-) 'BEGIN{split(b,type2fw,",")} {...}' .... just a suggestion to automate the treatment by importing the fieldwidth info from elsewhere... | |
| Apr 23, 2021 at 21:19 | history | edited | Ed Morton | CC BY-SA 4.0 | deleted 7 characters in body |
| Apr 23, 2021 at 14:28 | history | edited | Ed Morton | CC BY-SA 4.0 | added 135 characters in body |
| Apr 23, 2021 at 14:22 | history | edited | Ed Morton | CC BY-SA 4.0 | added 135 characters in body |
| Apr 23, 2021 at 14:16 | history | answered | Ed Morton | CC BY-SA 4.0 |