【发布时间】:2019-05-23 14:21:36
【问题描述】:
我正在处理一项任务,我必须阅读文本文件并将其中存在的每个单词作为输入,重要的是我应该通过使用 while 或任何其他循环来完成它(不使用awk 命令)
我尝试使用 while 循环,它正在读取文件,但我无法弄清楚接下来的步骤。
详情如下:
内容文件(源文件)
[root@localhost ~]# cat content.txt
Rantndeep,old spice,100,20
D-mart,toothbrush,30,20
more,sack,300,10
需要的输出
[root@localhost ~]# sh parser.sh
Today I went to Rantndeep Store bought old spice For Rs. 100 And paid 20 Rs.as a parking charges
Today I went to D-mart Store bought toothbrush For Rs. 30 And paid 20 Rs.as a parking charges
Today I went to more Store bought sack For Rs. 300 And paid 10 Rs.as a parking charges
我的脚本
[root@localhost ~]# cat p.sh
#/bin/bash
cat content.txt | while read a
do
echo $a
done
这只是打印上面提到的文件的内容我想通过使用任何循环来编写脚本,这样我就可以得到输出
[root@localhost ~]# sh parser.sh
Today I went to Rantndeep Store bought old spice For Rs. 100 And paid 20 Rs.as a parking charges
Today I went to D-mart Store bought toothbrush For Rs. 30 And paid 20 Rs.as a parking charges
Today I went to more Store bought sack For Rs. 300 And paid 10 Rs.as a parking charges
【问题讨论】:
-
请将您的所有代码/示例包装在 CODE TAGS 中。
-
你能详细说明一下我对这个世界很陌生吗?
-
请看这篇文章以供参考meta.stackexchange.com/questions/51144/…
-
@SKuser :您还应该定义什么是单词。例如,
abc,def和x100分别是一个词还是两个词? -
@SKuser : 用
fmt -1 content.txt替换cat content.txt怎么样?