Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 如何从所有文件中删除第一列并替换?_Unix_Sed_Cut_Tab Delimited - Fatal编程技术网

Unix 如何从所有文件中删除第一列并替换?

Unix 如何从所有文件中删除第一列并替换?,unix,sed,cut,tab-delimited,Unix,Sed,Cut,Tab Delimited,我有几个以制表符分隔的文件,例如,该文件如下所示: A213<TAB>foo bar<TAB>sentence A123<TAB>bar foo<TAB>sentence B84521<TAB>abc hello<TAB>world C984<TAB>def word<TAB>hello 我尝试了以下方法,但无效: $ cut -f2,3 file.txt | sed 's/<TAB>/

我有几个以制表符分隔的文件,例如,该文件如下所示:

A213<TAB>foo bar<TAB>sentence
A123<TAB>bar foo<TAB>sentence
B84521<TAB>abc hello<TAB>world
C984<TAB>def word<TAB>hello
我尝试了以下方法,但无效:

$ cut -f2,3 file.txt | sed 's/<TAB>/\s|||\s/g'
$cut-f2,3 file.txt | sed's//\s | | | s/g'
这样可以:

$ awk 'BEGIN{FS="\t"; OFS=" ||| "} {print $2, $3}' file
foo bar ||| sentence
bar foo ||| sentence
abc hello ||| world
def word ||| hello
这只是相应地定义输入和输出字段分隔符的问题。然后,打印第二个和第三个字段

使用
cut
+
sed
可以使用:

$ cut -d$'\t' -f2- < file | sed 's/\t/|||/' 
foo bar|||sentence
bar foo|||sentence
abc hello|||world
def word|||hello
$cut-d$'\t'-f2-
在所有情况下,请注意,您必须指明什么是字段分隔符。

这样可以:

$ awk 'BEGIN{FS="\t"; OFS=" ||| "} {print $2, $3}' file
foo bar ||| sentence
bar foo ||| sentence
abc hello ||| world
def word ||| hello
这只是相应地定义输入和输出字段分隔符的问题。然后,打印第二个和第三个字段

使用
cut
+
sed
可以使用:

$ cut -d$'\t' -f2- < file | sed 's/\t/|||/' 
foo bar|||sentence
bar foo|||sentence
abc hello|||world
def word|||hello
$cut-d$'\t'-f2-
在所有情况下,请注意,您必须指明什么是字段分隔符。

这样可以:

$ awk 'BEGIN{FS="\t"; OFS=" ||| "} {print $2, $3}' file
foo bar ||| sentence
bar foo ||| sentence
abc hello ||| world
def word ||| hello
这只是相应地定义输入和输出字段分隔符的问题。然后,打印第二个和第三个字段

使用
cut
+
sed
可以使用:

$ cut -d$'\t' -f2- < file | sed 's/\t/|||/' 
foo bar|||sentence
bar foo|||sentence
abc hello|||world
def word|||hello
$cut-d$'\t'-f2-
在所有情况下,请注意,您必须指明什么是字段分隔符。

这样可以:

$ awk 'BEGIN{FS="\t"; OFS=" ||| "} {print $2, $3}' file
foo bar ||| sentence
bar foo ||| sentence
abc hello ||| world
def word ||| hello
这只是相应地定义输入和输出字段分隔符的问题。然后,打印第二个和第三个字段

使用
cut
+
sed
可以使用:

$ cut -d$'\t' -f2- < file | sed 's/\t/|||/' 
foo bar|||sentence
bar foo|||sentence
abc hello|||world
def word|||hello
$cut-d$'\t'-f2-
在所有情况下,请注意,您必须指明什么是字段分隔符