Tux*_*ife 3 bash sed awk text-processing
我想转换
blue blue red green
Run Code Online (Sandbox Code Playgroud)
到:
color.1=blue color.2=blue color.3=red color.4=green
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何线索?sed、awk 等?
在 Bash 中:
colors="blue blue red green"
i=1
for c in $colors; do
echo -n "color.$((i++))=$c "
done
Run Code Online (Sandbox Code Playgroud)
命令行版本(易于复制和粘贴到终端)有 2 行 - 首先设置变量,然后设置主脚本:
colors="blue blue red green"; i=1
for c in $colors; do echo -n "color.$((i++))=$c "; done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
251 次 |
| 最近记录: |