use*_*398 2 sed awk text-processing columns
我的输入文件在第一列中有不同数量的空格(或没有空格)的位置
16504 16516
1650811 16520
1651 16524
16516111 16528
165204 16532
Run Code Online (Sandbox Code Playgroud)
我需要得到一个输出文件,其中第一列根本没有空格,同时保持第二列不变。
16504 16516
16508 16520
16512 16524
16516 16528
16520 16532
Run Code Online (Sandbox Code Playgroud)
如果这只是对齐问题,并且您想将数据排列成列:
$ column -t somefile
16504 16516
1650811 16520
1651 16524
16516111 16528
165204 16532
Run Code Online (Sandbox Code Playgroud)
所述-t
开关以column
将来自源数据创建一个表,自动:
-t, --table
Determine the number of columns the input contains and create a
table. Columns are delimited with whitespace, by default,
or with the characters supplied using the separator. Table output
is useful for pretty-printing.
Run Code Online (Sandbox Code Playgroud)
您可能会追求以下内容:
sed "s/^ *//" < your_file
Run Code Online (Sandbox Code Playgroud)
删除任何前导空格(用空字符串替换它们)。如果列之间还有可变数量的空格,则可以将其扩展为:
sed "s/^ *//;s/ */ /g" < your_file
Run Code Online (Sandbox Code Playgroud)
它(删除前导空格后)用固定字符串(在本例中为 4 个空格)替换任何出现的一个或多个空格。您可能还想\s
在匹配模式中使用代替普通空格来覆盖使用制表符的情况。