fdj*_*ant 3 bash sed awk text-processing
我有以下几行
3, 3, 100
4, 2, 50
8, 5, 80
.
.
.
Run Code Online (Sandbox Code Playgroud)
我想要以下输出
line starts at 3 and ends at 3 with value 100
line starts at 4 and ends at 2 with value 50
line starts at 8 and ends at 5 with value 80
.
.
.
Run Code Online (Sandbox Code Playgroud)
我尝试了以下操作:sed 's/^/line starts at /'然后将此命令应用于输出:sed 's/, / and ends at /'然后将此命令应用于输出sed 's/, / with value /'。有没有办法在一行中做到这一点?
ste*_*ver 12
awk 适合这种格式化输入 - 格式化输出:
awk -F, '{printf("line starts at %d and ends at %d with value %d\n", $1, $2, $3)}' file
line starts at 3 and ends at 3 with value 100
line starts at 4 and ends at 2 with value 50
line starts at 8 and ends at 5 with value 80
Run Code Online (Sandbox Code Playgroud)