1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excel列名を変換するシェルスクリプト(A→1、AA→27、XFD→16384…)

Last updated at Posted at 2016-05-29

コード

excc(excel_column_converter)
# !/bin/sh
echo $1 | grep -o '.' | tail -r | awk '{print "(26^"NR-1")*"$1}' |
sed -e 's/A/1/g' \
-e 's/B/2/g' \
-e 's/C/3/g' \
-e 's/D/4/g' \
-e 's/E/5/g' \
-e 's/F/6/g' \
-e 's/G/7/g' \
-e 's/H/8/g' \
-e 's/I/9/g' \
-e 's/J/10/g' \
-e 's/K/11/g' \
-e 's/L/12/g' \
-e 's/M/13/g' \
-e 's/N/14/g' \
-e 's/O/15/g' \
-e 's/P/16/g' \
-e 's/Q/17/g' \
-e 's/R/18/g' \
-e 's/S/19/g' \
-e 's/T/20/g' \
-e 's/U/21/g' \
-e 's/V/22/g' \
-e 's/W/23/g' \
-e 's/X/24/g' \
-e 's/Y/25/g' \
-e 's/Z/26/g' |
tr '\n' '+' | sed 's/+$//g' | bc

結果

$ ./excc A
1

$ ./excc AA
27

$ ./excc CDP
2148

$ ./excc XFD
16384

$ ./excc GGGG
127953

tail -r が使えない場合

tail -rtacに変えてください。

1
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?