How do I replace whitespaces with tabs in linux in a given text file?
The tr command in UNIX is a command line utility for translating or deleting characters.
vim Whitespace Convert tabs to spaces and spaces to tabs :retab! If you enable expandtab again :set expandtab then and run the :retab! command then all the tabs becomes spaces. If you want to do this for selected text then first select the text in visual mode.
UNEXPAND(1) User Commands UNEXPAND(1) NAME unexpand - convert spaces to tabs SYNOPSIS unexpand [OPTION]... [FILE]... DESCRIPTION Convert blanks in each FILE to tabs, writing to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -a, --all convert all blanks, instead of just initial blanks --first-only convert only leading sequences of blanks (overrides -a) -t, --tabs=N have tabs N characters apart instead of 8 (enables -a) -t, --tabs=LIST use comma separated LIST of tab positions (enables -a) --help display this help and exit --version output version information and exit . . . STANDARDS The expand and unexpand utilities conform to IEEE Std 1003.1-2001 (``POSIX.1'').
I think you can try with awk
awk -v OFS="\t" '$1=$1' file1
or SED if you preffer
sed 's/[:blank:]+/,/g' thefile.txt > the_modified_copy.txt
or even tr
tr -s '\t' < thefile.txt | tr '\t' ' ' > the_modified_copy.txt
or a simplified version of the tr solution sugested by Sam Bisbee
tr ' ' \\t < someFile > someFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With