简体   繁体   English

如何使用 awk 打印整个字符串中的每个单词?

[英]How to use awk to print every word from a whole string?

I declared variable (string) containing k names of queues, I want to delete.我声明了包含 k 个队列名称的变量(字符串),我想删除。

How can i "loop" through the string and delete each queue?如何“循环”字符串并删除每个队列?

I'm having trouble with the awk command.我在使用 awk 命令时遇到问题。

thanks a lot!多谢!

你可以试试下面的命令吗?

 awk '{for(i=1;i<=NF;i++) {printf "%s ", $i}; printf "\n"}' | xargs rm

there are many ways, I think the simplest will be方法很多,我觉得最简单的就是

$ vars="name1 name2 name3"
$ for v in $vars; do echo $v; done
name1
name2
name3

change echo to your script.将 echo 更改为您的脚本。

You can use xargs :您可以使用xargs

queues="q1 q2 q3 q4"
echo ${queues} | xargs -n1 echo "Remove"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用awk面对文件每一行中的第一个数字,并打印包含最大行的整行 - use awk to confront first number in every line of a file and print the whole line that contains the largest one 使用awk从具有空格的文本字符串的文件中打印打印 - Use awk to print print from a file that has a string of text with spaces 如何打印 word get from variable in specific line with AWK? - How to print word get from variable in specific line with AWK? 如何为awk中的每一行使用最大数量? - How to use the max number for every line in awk? 如果找到模式,如何使用awk打印“ hello” - How to use awk to print “hello” if pattern is found 如何使用AWK打印最高编号的行? - How to use AWK to print line with highest number? 如何使用grep,sed和awk在找到的模式后打印下一个单词? - How to print the next word after a found pattern with grep,sed and awk? 如何从第二行使用 awk &#39;{print $1*Number}&#39; 或告诉他忽略 NaN 值? - How to use awk '{print $1*Number}' from the second line or telling him to ignore NaN values? 如何使用awk(或剪切)从管道分隔的文件中每行打印最后一个字段? - How can I use awk (or cut) to print the last field per line from a pipe separated file? awk 检查文件 A 中列的值是否存在于文件 B 中,如果不存在则打印文件 A 的整行 - awk check if value from a column in file A exists in file B and if not print whole line of file A
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM