我试图从stdata.txt 中删除第一列和第二列,从stdata1.txt 中删除第二列。
数据.txt :
1 a 10
2 b 20
3 c 30
Run Code Online (Sandbox Code Playgroud)
studata1.txt :
i si
co oi
me zi
Run Code Online (Sandbox Code Playgroud)
这是我的 bash 文件:
cut -d -f -2 studata.txt >tmp1
cut -d -f 2- studata1.txt > tmp2
paste tmp1 tmp2 > c.txt
cat c.txt
Run Code Online (Sandbox Code Playgroud)
错误:
cut: the delimiter must be a single character
Run Code Online (Sandbox Code Playgroud)
当它用作参数时,您需要转义空格,即:
cut -d \ -f -2 studata.txt > tmp1
Run Code Online (Sandbox Code Playgroud)
注意 后有 2 个空格\
。第一个被转义并代表-d
选项的参数,而第二个将它与-f
选项分隔开。
你也可以把它放在单引号之间:
cut -d ' ' -f -2 studata.txt > tmp1
Run Code Online (Sandbox Code Playgroud)
或双引号之间:
cut -d " " -f -2 studata.txt > tmp1
Run Code Online (Sandbox Code Playgroud)
转义字符:如何去除单个字符的特殊含义。
单引号:如何禁止对字符序列的所有解释。
双引号:如何抑制大部分字符序列的解释。