使用bash读取文件,然后从提取的词执行命令 [英] Use bash to read a file and then execute a command from the words extracted

查看:133
本文介绍了使用bash读取文件,然后从提取的词执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件:

 你好
世界

我想用一个脚本语言( BASH )来执行读取命令每个文件上面,然后将其插入到命令

有随后循环至列表中的下一个字(在新的一行的每个字)。
它停止当它到达文件的末尾


进展是与此类似:

阅读第一文件上方

字插入到命令

 命令字>字


  • 这将其输出到一个文本文件;用一句话作为文件名。

重复这一过程,但旁边的第n (每次一个新行)。

在到达上面的文件年底

终止进程。


在bash命令的结果 文件上面:

您好:

 命令UPON字的结果打招呼

世界:

 命令UPON WORD世界RESULT


解决方案

您可以使用for循环来做到这一点。像..

 在'猫WORD FILE`

   回声$ WORD
   命令$ WORD> $ WORD
DONE

FILE:

hello
world

I would like to use a scripting language (BASH) to execute a command that reads each WORD in the FILE above and then plugs it into a command.

It then loops to the next word in the list (each word on new line). It stops when it reaches the end of the FILE.


Progression would be similar to this:

Read first WORD from FILE above

Plug word into command

command WORD > WORD

  • which will output it to a text file; with word as the name of the file.

Repeat this process, but with next to nth WORD (each on a new line).

Terminate process upon reaching the end of FILE above.


Result of BASH command on FILE above:

hello:

RESULT OF COMMAND UPON WORD hello

world:

RESULT OF COMMAND UPON WORD world

解决方案

You can use the "for" loop to do this. something like..

for WORD in `cat FILE`
do
   echo $WORD
   command $WORD > $WORD
done

这篇关于使用bash读取文件,然后从提取的词执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆