Respostas:
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'').
Eu acho que você pode tentar com awk
awk -v OFS="\t" '$1=$1' file1
ou SED se você preferir
sed 's/[:blank:]+/,/g' thefile.txt > the_modified_copy.txt
ou mesmo tr
tr -s '\t' < thefile.txt | tr '\t' ' ' > the_modified_copy.txt
ou uma versão simplificada da solução tr sugerida por Sam Bisbee
tr ' ' \\t < someFile > someFile
tr ' ' \\t < someFile > someFile
ls -l | sed "s/ \+/ /g"
awk -v OFS="\t" '$1=$1' file1percebi que se você tem uma linha começando com o número 0 (por exemplo 0 1 2), a linha será omitida do resultado.
Usando Perl :
perl -p -i -e 's/ /\t/g' file.txt
perl -p -i -e 's/\t/ /g' *.java
melhor comando tr :
tr [:blank:] \\t
Isso limpará a saída de, digamos, descompactar -l , para processamento posterior com grep, cut, etc.
por exemplo,
unzip -l some-jars-and-textfiles.zip | tr [:blank:] \\t | cut -f 5 | grep jar
tr [:blank:] \\t
Faça download e execute o seguinte script para converter recursivamente as guias virtuais em guias rígidas em arquivos de texto simples.
Coloque e execute o script de dentro da pasta que contém os arquivos de texto simples.
#!/bin/bash
find . -type f -and -not -path './.git/*' -exec grep -Iq . {} \; -and -print | while read -r file; do {
echo "Converting... "$file"";
data=$(unexpand --first-only -t 4 "$file");
rm "$file";
echo "$data" > "$file";
}; done;
Você também pode usar astyle. Achei bastante útil e tem várias opções também:
Tab and Bracket Options:
If no indentation option is set, the default option of 4 spaces will be used. Equivalent to -s4 --indent=spaces=4. If no brackets option is set, the
brackets will not be changed.
--indent=spaces, --indent=spaces=#, -s, -s#
Indent using # spaces per indent. Between 1 to 20. Not specifying # will result in a default of 4 spaces per indent.
--indent=tab, --indent=tab=#, -t, -t#
Indent using tab characters, assuming that each tab is # spaces long. Between 1 and 20. Not specifying # will result in a default assumption of
4 spaces per tab.`
Se você está falando sobre substituir todos os espaços consecutivos em uma linha por uma tabulação, então tr -s '[:blank:]' '\t'.
[root@sysresccd /run/archiso/img_dev]# sfdisk -l -q -o Device,Start /dev/sda
Device Start
/dev/sda1 2048
/dev/sda2 411648
/dev/sda3 2508800
/dev/sda4 10639360
/dev/sda5 75307008
/dev/sda6 96278528
/dev/sda7 115809778
[root@sysresccd /run/archiso/img_dev]# sfdisk -l -q -o Device,Start /dev/sda | tr -s '[:blank:]' '\t'
Device Start
/dev/sda1 2048
/dev/sda2 411648
/dev/sda3 2508800
/dev/sda4 10639360
/dev/sda5 75307008
/dev/sda6 96278528
/dev/sda7 115809778
Se você está falando sobre a substituição de todos os espaços em branco (por exemplo, espaço, tabulação, nova linha, etc.), então tr -s '[:space:]'.
[root@sysresccd /run/archiso/img_dev]# sfdisk -l -q -o Device,Start /dev/sda | tr -s '[:space:]' '\t'
Device Start /dev/sda1 2048 /dev/sda2 411648 /dev/sda3 2508800 /dev/sda4 10639360 /dev/sda5 75307008 /dev/sda6 96278528 /dev/sda7 115809778
Se você está falando sobre como consertar um arquivo danificado por tab, use expande unexpandconforme mencionado em outras respostas.
Isso substituirá os espaços consecutivos por um espaço (mas não a tabulação).
tr -s '[:blank:]'
Isso substituirá os espaços consecutivos por uma tabulação.
tr -s '[:blank:]' '\t'
-cele substitui caracteres consecutivos que não são espaços.
troused.