Last active
June 25, 2016 08:09
-
-
Save acro5piano/a0a9fcb2a58cc6805e6987122155e703 to your computer and use it in GitHub Desktop.
CSVファイルから特定の列を取り出す自作関数 ref: http://qiita.com/acro5piano/items/26c4926b243e615a2d77
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat <<EOF > test.txt | |
a b c | |
d e f | |
EOF | |
# cutを使う場合 | |
cat test.txt | cut -d ' ' -f 1,3 | |
#=> a c | |
#=> d f | |
# awkで同じことをする | |
cat test.txt | awk '{print $1, $3}' | |
#=> a c | |
#=> d f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colprint(){ | |
options='' | |
while getopts F: OPT; do | |
options="$options -$OPT $OPTARG" | |
done | |
shift $((OPTIND - 1)) | |
command='' | |
for str in $@; do | |
command=`echo $command '$'$str, ` | |
done | |
awk $options "{print `echo $command | sed 's/,$//g'`}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat <<EOF | colprint 1 3 | |
a b c | |
d e f | |
EOF | |
#=> a c | |
#=> d f | |
cat <<EOF | colprint -F ,, 1 3 | |
a,,b,,c | |
d,,e,,f | |
EOF | |
#=> a c | |
#=> d f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment