Writing shell script to print a certain number of lines with certain arguments

前端 未结 3 1942
傲寒
傲寒 2021-01-28 15:09

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          


        
3条回答
  •  既然无缘
    2021-01-28 15:34

    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
    

    Output:

    $ 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
    

提交回复
热议问题