bash 如何从带有制表符分隔列的文件中提取第一列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15138782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:41:48  来源:igfitidea点击:

How to extract the first column from a file with tab-separated columns

bashshell

提问by Azzeddine

I have a file with the following format

我有一个具有以下格式的文件

  EMAIL[TAB]NAME[TAB]ADRESSE[TAB]...
  [email protected][TAB]toto[TAB]tatatata....
  [email protected][TAB]toto[TAB]tatatata....

[TAB] ===> tabulation

[TAB] ===> 制表

I would like with a bash script to remove all columns except the email:

我想用 bash 脚本删除除电子邮件之外的所有列:

the final outputshould be something like:

最终输出应该是这样的:

  EMAIL
  [email protected]
  [email protected]

回答by beny23

You could use

你可以用

cut -f1 < inputfile.txt

回答by Rawkode

awk 'BEGIN { FS="\t" } { print  }' a

回答by William

Try this:

尝试这个:

sed -e 's/\t.*//' yourfile

(The answer using cutwould be my first choice though.)

(尽管答案 usingcut将是我的第一选择。)