BASH 脚本和 AWK 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24822005/
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 10:54:14  来源:igfitidea点击:

Difference between BASH Scripting and AWK

linuxbashshellawk

提问by Sri

What is the difference between BASH Scripting and AWK?

BASH Scripting 和 AWK 有什么区别?

When would I use one over the other?

我什么时候会使用一个?

回答by Am_I_Helpful

I think that from bash Scriptingyou are referring to general scripting that performs everything.

我认为bash Scripting您指的是执行所有操作的通用脚本。

But,awk is basically an independent tool which can be called independently,even without invoking the bash shell(or any shell)!It is an independent tool as mentioned by tristan!

但是,awk 基本上是一个可以独立调用的独立工具,即使不调用 bash shell(或任何 shell)!它是一个独立的工具tristan

bash Scriptingis used for performing any kind of operations using the shell!In fact,what you can achieve through awkcan be achieved directly in bash scripts using other filters or even grep regex.And in addition,you can perform many other things which is not achievable through awk!

bash Scripting用于使用shell执行任何类型的操作!实际上,您可以通过awk使用其他过滤器甚至grep正则表达式在bash脚本中直接实现。此外,您可以执行许多其他无法通过的操作awk

awkis an excellent filter and report writer.Many UNIX utilities generates rows and columns of information. AWK is an excellent tool for processing these rows and columns, and is easier to use AWK than most conventional programming languages. It can be considered to be a pseudo-C interpretor, as it understands the same arithmatic operators as C. AWK also has string manipulation functions, so it can search for particular strings and modify the output. AWK also has associative arrays, which are incredible useful, and is a feature most computing languages lack.

awk是一个出色的过滤器和报告编写器。许多 UNIX 实用程序生成信息的行和列。AWK 是处理这些行和列的绝佳工具,与大多数传统编程语言相比,AWK 更易于使用。它可以被认为是一个伪 C 解释器,因为它理解与 C 相同的算术运算符。AWK 还具有字符串操作功能,因此它可以搜索特定的字符串并修改输出。AWK 还具有关联数组,这非常有用,并且是大多数计算语言所缺乏的功能。

回答by Am_I_Helpful

Awk is just another tool that you can call easily from a Bash script.

Awk 只是另一个可以从 Bash 脚本轻松调用的工具。

You would call awk when you need to filter data and a built-in function to Bash doesn't (or doesn't easily) do what you need. You can use Bash to define your logical flow and tools like sedor awkto manipulate data or do work. Awk is good at filtering data from files.

当您需要过滤数据并且 Bash 的内置函数不能(或不容易)执行您需要的操作时,您将调用 awk。您可以使用猛砸来定义你的逻辑流程和工具,如sedawk操纵数据或做的工作。awk 擅长从文件中过滤数据。

For what it's worth, I've never heard of someone considering a script to not be a "bash script" because it invokes Awk.

就其价值而言,我从未听说有人认为脚本不是“bash 脚本”,因为它调用了 Awk。