我有一个文件,如下所示:
1234
ABCD
EFGH
Run Code Online (Sandbox Code Playgroud)
我想将其转换为以下内容:
2341
BCDA
FGHE
Run Code Online (Sandbox Code Playgroud)
实际文件有 4,000 字,所以我想以有效的方式做到这一点。我尝试使用 command cut -c 2-4,1 file.txt,但它产生与输入完全相同的输出。我在想我可以使用 3 个不同的命令:
cut -c 1 file.txt > temp1.txt
cut -c 2-4 file.txt > temp2.txt
// combine the two with paste or pr
Run Code Online (Sandbox Code Playgroud)
...但我更喜欢单个命令,因为我需要稍加修改多次运行它,因此运行一个命令比每次运行 3 个命令更不容易出错。
有没有办法将 2 个 cut 语句合并为一个?就像是:
cut -c 1 file.txt | pr (cut -c 2-4 file.txt)
Run Code Online (Sandbox Code Playgroud)
或者有没有更好的方法来做到这一点?