AI generated bash scripts? 😅
My brain 🎓 generated this oneliner you might want to check out and modify for your own needs:
Maestro MHO Ports Dump - Sorted & Colored
By looking at this part of your script:
orch_stat -p | awk '
BEGIN {FS="|"}
/^\+/ { next } # Skip separator lines
/^\|[ ]*Physical Port/ { next } # Skip header line
/^\|/ {
if (NF != 14) next # Only process lines with 14 fields (12 data fields)
row=""
for(i=2; i<=13; i++) { # Extract fields 2 to 13 (data columns)
f=$i
gsub(/^[ \t]+|[ \t]+$/, "", f) # Trim leading/trailing whitespace
row = row f "\t"
}
sub(/\t$/, "", row) # Remove trailing tab
print row
}
'
I instantly had to shrink and optimize it into this oneliner:
orch_stat -p|awk '/\// {gsub(/\s*\|\s*/, "\t"); sub(/^\t|\t$/, ""); print}'
As you'll see, it runs slightly faster.
It's generally a good practice to avoid unnecessary subshells, therefore I suggest to continue with |while read line; do
, just as Sven did here.