IsraelTorres icon

run-each-row-and-column.sh

IsraelTorres | PRO | 03/18/12 12:41:18 AM UTC | 0 ⭐ | 341 👁️ | Never ⏰ | []
Bash |

730 B

|

None

|

0 👍

/

0 👎

#!/bin/bash
# ./run-each-row-and-column.sh
# Israel Torres
# 20120317
# Input a tab delimited file with two columns 
# Use three examples ending with the built-in
#
# create the tab delimted multiline text file
echo -e "col1\tcol2\ndata1\tdata2" > data.txt
#
SAVEIFS=$IFS; IFS=$(echo -en "\n\b");
for x in $(cat data.txt)
do 
# using cut
#col1=$(echo $x | cut -f 1)
#col2=$(echo $x | cut -f 2)
#echo -e "[column 1]:$col1\t[column 2]:$col2"
#
# using awk
#col1=$(echo $x | awk '{print $1}')
#col2=$(echo $x | awk '{print $2}')
#echo -e "[column 1]:$col1\t[column 2]:$col2"
#
# using builtin
btab=$(echo -ne "\t") # create tab
col1=$(echo ${x/$btab*/})
col2=$(echo ${x/*$btab/})
echo -e "[column 1]:$col1\t[column 2]:$col2"
#
done
IFS=$SAVEIFS
#EOF

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎