bash - 使用 shell 脚本处理处理制表符分隔文件

标签 bash shell scripting sed awk

通常我会使用 Python/Perl 来执行此过程,但我发现自己(出于政治原因)不得不使用 bash shell 来完成此操作。

我有一个很大的制表符分隔文件,其中包含六列,第二列是整数。我需要编写一个解决方案的 shell 脚本,以验证该文件确实是六列并且第二列确实是整数。我假设我需要在某处使用 sed/awk。问题是我不太熟悉 sed/awk。任何建议将不胜感激。

非常感谢! 礼来

最佳答案

呆呆的:

BEGIN {
  FS="\t"
}

(NF != 6) || ($2 != int($2)) {
  exit 1
}

调用如下:

if awk -f colcheck.awk somefile
then
  # is valid
else
  # is not valid
fi

关于bash - 使用 shell 脚本处理处理制表符分隔文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2781000/

相关文章:

xml - 将显示 XML 编码的 Linux 脚本

linux - 让 cron 作业每 30 分钟运行一次 - 使用 cron.hourly?

shell - 为什么 emacs comint 模式不将字符串作为 shell 处理?

windows - Powershell脚本自动输入端口号

shell - KornShell bool 条件逻辑

java - Java 应用程序中 "end user"的脚本语言

string - 解析命令行参数来处理 bash 中的文件列表?

c - 新交所飞地 : Where the actual function that does the procession goes and how it gets compiled

bash - 删除除最后一行以外的所有以相同字符串开头的行

linux - dialog --menu 选中的选项