Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Return two variables in awk
  2. ret=$(ls -la | awk '{print $3 " "  $9}')
  3. usr=$(echo $ret | awk '{print $1}')
  4. fil=$(echo $ret | awk '{print $2}')
  5.        
  6. ls -la | awk -r usr=x -r fil=y '{x=$3; y=$9}'
  7.        
  8. usr=""
  9. fil=""
  10. while read u f; do usr="$usrn$u"; fil="$filn$f"; done < <(ls -la | awk '{print $3 " "  $9}')
  11.        
  12. while read u f; do usr="$usrn$u"; fil="$filn$f"; done <<< $(ls -la | awk '{print $3 " "  $9}')
  13.        
  14. $ usr=""
  15. $ fil=""
  16. $ while read u f; do usr="$usrn$u"; fil="$filn$f"; done << EOF
  17. > $(ls -la | awk '{print $3 " "  $9}')
  18. > EOF
  19.        
  20. eval $(ls -la | awk '{usr = $3 " " usr;fil = $9 " " fil} END{print "usr=""usr"";fil=""fil"""}')
  21.        
  22. echo -e $usr
  23. echo -e $fil
  24.        
  25. $time <three line approach>
  26.  
  27. real    0m0.017s
  28. user    0m0.006s
  29. sys     0m0.011s
  30.  
  31. $time <one line approach>
  32. real    0m0.009s
  33. user    0m0.004s
  34. sys     0m0.007s
  35.        
  36. unset      FILES
  37. declare -A FILES
  38. FILES=( ls -la | awk '{print $9 " "  $3}' )
  39.        
  40. for fil in ${!FILES[@]}
  41. do
  42.   usr=${FILES["$fil"]}
  43.   echo -e "$usr" "t" "$fil"
  44. done
  45.        
  46. ret_ary=( $(command | awk '{print $3, $9}') )
  47. usr=${ret_ary[0]}
  48. fil=${ret_ary[1]}
  49.  
  50. set -- $(command  | awk '{print $3, $9}')
  51. usr=$1
  52. fil=$2
  53.        
  54. ret_ary=( $(command | awk '{print $3, $9}') )
  55. usr=${ret_ary[0]}
  56. fil=${ret_ary[1]}
  57.  
  58. set -- $(command  | awk '{print $3, $9}')
  59. usr=$1
  60. fil=$2
  61.        
  62. ret_ary=( $(command | awk '{print $3, $9}') )
  63. usr=${ret_ary[0]}
  64. fil=${ret_ary[1]}
  65.  
  66. set -- $(command  | awk '{print $3, $9}')
  67. usr=$1
  68. fil=$2
  69.        
  70. ret_ary=( $(command | awk '{print $3, $9}') )
  71. usr=${ret_ary[0]}
  72. fil=${ret_ary[1]}
  73.  
  74. set -- $(command  | awk '{print $3, $9}')
  75. usr=$1
  76. fil=$2