indent.txt uses leading spaces corresponding to tab stops of eight columns.
Replace convertible leading spaces with tabs while preserving display positions.
Which GNU coreutils command is appropriate?
unexpand converts spaces to tabs, while expand performs the opposite conversion. The -t option sets tab stops.
Detailed explanation
expand -t 8 indent.txtIncorrect. expand converts tabs into spaces, the opposite direction.
Incorrect. expand converts tabs into spaces, the opposite direction.
tr ' ' '\t' < indent.txtIncorrect. Replacing every space one-for-one with a tab does not preserve columns.
Incorrect. Replacing every space one-for-one with a tab does not preserve columns.
unexpand -t 8 indent.txtCorrect. unexpand -t 8 converts suitable leading spaces using tab stops of eight.
Correct. unexpand -t 8 converts suitable leading spaces using tab stops of eight.
cut -c9- indent.txtIncorrect. cut -c9- removes leading characters and loses indentation.
Incorrect. cut -c9- removes leading characters and loses indentation.
Try it yourself
An example you can run in a temporary verification environment.
printf ' item\n' | unexpand -t 8 | od -An -tx1Expected result
先頭バイトが09(tab)、続いてitemと改行Key points
- unexpand converts spaces to tabs
- expand converts tabs to spaces
- -t sets tab stops
Notes
- Environment: GNU coreutils 9.x / 標準入力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.