bash - 如何从字符串中获取单词 x
问题描述
我想逐行读取文件,如下所示:
while read line;
do
set -- $line
c=$# #count words and save as $c
r=$(( RANDOM%c ))
#here i'd like to get the word on position r from $line
done < words.txt
我知道,我可以得到如下的单词 1:
set -- $line
echo $1
但是如何将 1 替换为保存在 $r 中的整数?
解决方案
推荐阅读
- reactjs - Internet Explorer - ReactJS 在刷新后不会丢失数据 (F5)
- css - CSS 改革 ASCI 图像
- ios - 无法导入桥接头“/MyProject-Bridging.h”
- asp.net-core-mvc - 从 MVC 控制器在同一个应用程序中使用 Web API
- sass - Sass 在一个循环中混合多个属性
- c# - BooleanToVisibilityConverter 折叠/显示 TabItem
- c - 冒泡排序法的小问题
- python-3.x - 使用 pandas 多索引进行搜索优化
- javascript - 使用 json 制作动态 HTML 表格
- c# - 如何使用 C# 代码检索另一个对象内部的对象的所有属性?