linux - 如何在 Bash 脚本中使用 Awk [有问题]?

标签 linux bash scripting awk

所以我一直在处理与 awk 相关的作业。一切都差不多完成了,除了当我将命令放入 bash 脚本时(自动运行其中的 11 个)我没有得到任何输出。我是否缺少 awk 需要在脚本中工作的某种语法?谢谢!

我只给你前四个给你一个想法:

#!/bin/sh
##VARIABLES
W=/usr/share/dict/words
C=cars_file
P=/etc/passwd


##PROBLEM EXAMPLE
#display problem number
#display command
#run command
#echo whitespace


##PROBLEMS
 echo ">PROBLEM 01"
 echo    "awk '/zzan/ {print}' $W | head"          #contains 'zzan'
          awk '/zzan/ {print}' $W | head           #pipe to head
 echo

 echo ">PROBLEM 02"
 echo    "awk '/^[aeiou].*[ou]rch$/ {print}' $W | head"       #start w/lowercase vowel
 echo     awk '/^[aeiou].*[ou]rch$/ {print}' $W | head        #end in orch/urch
 echo                                                         #pipe to head

 echo ">PROBLEM 03"
 echo    "awk '/chevy/ {print}' $C"                 #display all records
 echo     awk '/chevy/ {print}' $C                  #of all chevys
 echo

 echo ">PROBLEM 04"
 echo    "awk '$1 ~ /o/ {print}' $C"               #display all records
 echo     awk '$1 ~ /o/ {print}' $C                #contains 'o' in column 1
 echo

`

最佳答案

第一个 awk 条目应该可以正常工作(假设您的 awk 脚本执行您想要的操作。其他三个有一个错误的前导 echo,因此只是回显命令而不是运行命令。

关于linux - 如何在 Bash 脚本中使用 Awk [有问题]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20079819/

相关文章:

python - 如何迭代文件夹中的文件以移动具有特定扩展名的每个文件

powershell - 2个整数参数调用函数时出错

Bash - 检查哪个变量不等于零

linux - 这个脚本会在超过95%的物理内存时自动重启Tomcat

linux - 如何(几乎)防止 FT232R(uart)接收数据丢失?

linux - 从第二个元素开始循环 - Shell 脚本

linux - 如何使用linux grep命令?

node.js - npm 脚本忽略 grep 命令的参数

bash - Powershell 中的 CDPATH 功能?

linux - 从 db 中获取记录并将其分配给一个数组以用于 Linux bash 脚本中的邮件报告