Se todos os seus comandos e argumentos não contiverem #
e um outro caractere (digamos, o caractere ASCII dado pelo byte 1), você poderá inserir esse outro caractere como um separador extra e usar column
para alinhar os comentários (veja esta resposta ). Então, algo como:
$ sed $'s/#/$ sed $'s/#/$ sed $'s/#/$ sed $'s/#/%pre%1#/;s/^$/%pre%1/' input-file | column -ts $'%pre%1'
# Lines starting with # stay the same
# Empty lines stay the same
# only lines with comments should change
ls # show all major directories
# and other things
cd # The cd command - change directory
# will allow the user to change between file directories
touch # The touch command, the make file command
# allows users to make files using the Linux CLI # example, cd ~
bar foo baz # foo foo foo
1#/' input-file | column -ets $'%pre%1'
# Lines starting with # stay the same
# Empty lines stay the same
# only lines with comments should change
ls # show all major directories
# and other things
cd # The cd command - change directory
# will allow the user to change between file directories
touch # The touch command, the make file command
# allows users to make files using the Linux CLI # example, cd ~
bar foo baz # foo foo foo
1#/;s/^$/%pre%1/' input-file | column -ts $'%pre%1'
# Lines starting with # stay the same
# Empty lines stay the same
# only lines with comments should change
ls # show all major directories
# and other things
cd # The cd command - change directory
# will allow the user to change between file directories
touch # The touch command, the make file command
# allows users to make files using the Linux CLI # example, cd ~
bar foo baz # foo foo foo
1#/' input-file | column -ets $'%pre%1'
# Lines starting with # stay the same
# Empty lines stay the same
# only lines with comments should change
ls # show all major directories
# and other things
cd # The cd command - change directory
# will allow the user to change between file directories
touch # The touch command, the make file command
# allows users to make files using the Linux CLI # example, cd ~
bar foo baz # foo foo foo
Se o column
não suportar -e
para evitar a eliminação de linhas vazias, você poderá adicionar algo a linhas vazias (por exemplo, um espaço ou o caractere separador usado acima):