IsraelTorres

run-each-row-and-column.sh

Mar 17th, 2012
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # ./run-each-row-and-column.sh
  3. # Israel Torres
  4. # 20120317
  5. # Input a tab delimited file with two columns
  6. # Use three examples ending with the built-in
  7. #
  8. # create the tab delimted multiline text file
  9. echo -e "col1\tcol2\ndata1\tdata2" > data.txt
  10. #
  11. SAVEIFS=$IFS; IFS=$(echo -en "\n\b");
  12. for x in $(cat data.txt)
  13. do
  14. # using cut
  15. #col1=$(echo $x | cut -f 1)
  16. #col2=$(echo $x | cut -f 2)
  17. #echo -e "[column 1]:$col1\t[column 2]:$col2"
  18. #
  19. # using awk
  20. #col1=$(echo $x | awk '{print $1}')
  21. #col2=$(echo $x | awk '{print $2}')
  22. #echo -e "[column 1]:$col1\t[column 2]:$col2"
  23. #
  24. # using builtin
  25. btab=$(echo -ne "\t") # create tab
  26. col1=$(echo ${x/$btab*/})
  27. col2=$(echo ${x/*$btab/})
  28. echo -e "[column 1]:$col1\t[column 2]:$col2"
  29. #
  30. done
  31. IFS=$SAVEIFS
  32. #EOF
RAW Paste Data