string - put two concatenatend var in a command - shell bash -


i have problem script. have follow script:

while read line;      ifs=' '                                                                                                                              #sostituisco in ifs il carattere di default con quello di spazio     i=0     campo in $line;         (( i++ ))         if [[ $i -eq 1 ]] ;                                                 nome="$campo"         elif [[ $i -eq 2 ]] ;                                                cognome="$campo"         fi     done     nome_file=$nome\_$cognome                                            echo $nome_file      j=$(find /home/ubuntu/scrivania/contatti -name 'nome_file*' | wc -l)     echo $j       done < $rubrica 

the file rubrica contains rows that:

andrea bargnani 6956959388 2632634643 2012/05/19  chris bosh 87654323234 78675432334 2014/06/16  zlatan ibrahimovic 2937485929 1938472639 2003/06/30  andrea mantovani 3402948586 0459687124 2015/01/25  andrea mantovani 3476589456 0451234567 2016/07/05  andrea mantovani 3478765434 67654334567 2011/09/10  marco polo 735636 36546456 2011/09/10 

it take file rubrica in input , each line save in var nome firs column , in second var cognome second column. so, first row i'll have

nome=andrea cognome=bargnani 

after loop, script concatenate 2 var underscore in new var called nome_file. use var (nome_file) in command. problem dont know how put var in command. syntax?

you use $nome_file this:

j=$(find /home/ubuntu/scrivania/contatti -name "$nome_file*" | wc -l) 

...but loop slow if there many lines in $rubrica.

instead, use awk, e.g.:

awk '{printf "%s_%s\n", $1, $2}' $rubrica | while read nome_file;     echo $nome_file     j=$(find /home/ubuntu/scrivania/contatti -name 'nome_file*' | wc -l)     echo $j      done 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -