编写shell脚本打印一定数量的某些参数线 [英] Writing shell script to print a certain number of lines with certain arguments

查看:180
本文介绍了编写shell脚本打印一定数量的某些参数线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个变量,每个变量包含五个values​​.I想一个打印五行与五个值从五个参数的一个
例如:

I have 5 variables and each variables contains five values.I want to print five lines with the five values from five variables one by one For example

$a=1 2 3 4 5
$b=4 2 3 4 5
$c=8 9 7 6 5
$d= 8 7 6 5 4
$e=5 6 7 3 3

我要打印五行这种格式

I want to print five lines in this format

My options was a=1,b=4,c=8,d=8and e=5

My  options was a=2,b=2,c=9,d=7 and e=6

等高达五个值。

我糊涂了在使用loops.Can谁能帮我提供循环脚本获得以下输出。

I got confused in using the loops.Can anyone help me to provide loops in script to obtain the following output.

推荐答案

使用该 AWK 命令一个bash循环:

Using this awk command with a bash loop:

for i in {1..5}; do
awk '{printf "My options was a=%d, b=%d, c=%d, d=%d and e=%d\n", $1, $2, $3, $4, $5}' <<< $(awk '{print $'$i'}' <(echo -e "$a\n$b\n$c\n$d\n$e") | tr $'\n' ' '); done

输出:

$ a='1 2 3 4 5'
$ b='4 2 3 4 5'
$ c='8 9 7 6 5'
$ d='8 7 6 5 4'
$ e='5 6 7 3 3'
$ for i in {1..5}; do
awk '{printf "My options was a=%d, b=%d, c=%d, d=%d and e=%d\n", $1, $2, $3, $4, $5}' <<< $(awk '{print $'$i'}' <(echo -e "$a\n$b\n$c\n$d\n$e") | tr $'\n' ' '); done
My options was a=1, b=4, c=8, d=8 and e=5
My options was a=2, b=2, c=9, d=7 and e=6
My options was a=3, b=3, c=7, d=6 and e=7
My options was a=4, b=4, c=6, d=5 and e=3
My options was a=5, b=5, c=5, d=4 and e=3

这篇关于编写shell脚本打印一定数量的某些参数线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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