Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. VALUES="
  2. val1 ;val2 ;val3
  3. another1;another2;another3
  4. "
  5.  
  6. VALUES="
  7. val1 ;val2 ;val3
  8. another1;another2;another3
  9. "
  10. echo "$VALUES" | while IFS=' ;' read v1 v2 v3; do
  11. [[ -z $v1 && -z $v2 && -z $v3 ]] && continue
  12. echo "v1=$v1 v2=$v2 v3=$v3"
  13. done
  14.  
  15. v1=val1 v2=val2 v3=val3
  16. v1=another1 v2=another2 v3=another3
  17.  
  18. typeset -a values
  19. typeset -i i=0
  20. echo "$VALUES" | while IFS=' ;' read v1 v2 v3; do
  21. [[ -z $v1 && -z $v2 && -z $v3 ]] && continue
  22. values[i]=$v1
  23. values[i+1]=$v2
  24. values[i+2]=$v3
  25. ((i+=3))
  26. done
  27.  
  28. for i in "${!values[@]}"; do printf "%dt%sn" $i "${values[i]}"; done
  29.  
  30. 0 val1
  31. 1 val2
  32. 2 val3
  33. 3 another1
  34. 4 another2
  35. 5 another3
  36.  
  37. echo "$VALUES"|awk -F' *; *' 'NF>1{print $1, $2, $3}'
  38. val1 val2 val3
  39. another1 another2 another3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement