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-
在所有情况下,请注意,您必须指明什么是字段分隔符