Skip to content

Commit

Permalink
Merge pull request #48 from cdlab-sit/kumbikumbiSIC
Browse files Browse the repository at this point in the history
Kumbikumbi sic
  • Loading branch information
Hikaru-Morita authored Mar 2, 2019
2 parents ccde4b6 + 5ec7398 commit aaf0f01
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 54 deletions.
54 changes: 0 additions & 54 deletions kumbikumbiSIC/04_pre.py

This file was deleted.

Empty file removed kumbikumbiSIC/09_sub.py
Empty file.
97 changes: 97 additions & 0 deletions kumbikumbiSIC/10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#行数をカウントせよ.確認にはwcコマンドを用いよ.

file_name = "hightemp.txt"
lines = 0

with open(file_name) as file:
lines = len(file.readlines())
#with文なのでcloseが必要ない

print(lines)


'''
以下コマンドラインのコピー
~/s/1/kumbikumbiSIC ❯❯❯ wc -l hightemp.txt kumbikumbiSIC
24 hightemp.txt
以下 man wc の内容
~/s/1/kumbikumbiSIC ❯❯❯ man wc kumbikumbiSIC
WC(1) BSD General Commands Manual WC(1)
NAME
wc -- word, line, character, and byte count
SYNOPSIS
wc [-clmw] [file ...]
DESCRIPTION
The wc utility displays the number of lines, words, and bytes contained in each input
file, or standard input (if no file is specified) to the standard output. A line is
defined as a string of characters delimited by a <newline> character. Characters
beyond the final <newline> character will not be included in the line count.
A word is defined as a string of characters delimited by white space characters.
White space characters are the set of characters for which the iswspace(3) function
returns true. If more than one input file is specified, a line of cumulative counts
for all the files is displayed on a separate line after the output for the last file.
The following options are available:
-c The number of bytes in each input file is written to the standard output.
This will cancel out any prior usage of the -m option.
-l The number of lines in each input file is written to the standard output.
-m The number of characters in each input file is written to the standard out-
put. If the current locale does not support multibyte characters, this is
equivalent to the -c option. This will cancel out any prior usage of the -c
option.
-w The number of words in each input file is written to the standard output.
When an option is specified, wc only reports the information requested by that
option. The order of output always takes the form of line, word, byte, and file
name. The default action is equivalent to specifying the -c, -l and -w options.
If no files are specified, the standard input is used and no file name is displayed.
The prompt will accept input until receiving EOF, or [^D] in most environments.
ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of wc as
described in environ(7).
EXIT STATUS
The wc utility exits 0 on success, and >0 if an error occurs.
EXAMPLES
Count the number of characters, words and lines in each of the files report1 and
report2 as well as the totals for both:
wc -mlw report1 report2
COMPATIBILITY
Historically, the wc utility was documented to define a word as a ``maximal string of
characters delimited by <space>, <tab> or <newline> characters''. The implementa-
tion, however, did not handle non-printing characters correctly so that `` ^D^E ''
counted as 6 spaces, while ``foo^D^Ebar'' counted as 8 characters. 4BSD systems
after 4.3BSD modified the implementation to be consistent with the documentation.
This implementation defines a ``word'' in terms of the iswspace(3) function, as
required by IEEE Std 1003.2 (``POSIX.2'').
SEE ALSO
iswspace(3)
STANDARDS
The wc utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'').
HISTORY
A wc command appeared in Version 1 AT&T UNIX.
BSD February 23, 2005 BSD
~/s/1
'''
39 changes: 39 additions & 0 deletions kumbikumbiSIC/11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
file_name = "hightemp.txt"

with open(file_name) as file:
lines = file.read()
print("変更前:\n",lines)
print("変更後:\n",lines.replace('\t', " "))
# なぜスペースがでるか不明、誰か教えてください

#with文なのでcloseが必要ない

'''
以下コマンドラインのコピー
~/s/1/kumbikumbiSIC ❯❯❯ tr "\t" " " < hightemp.txt kumbikumbiSIC
高知県 江川崎 41 2013-08-12
埼玉県 熊谷 40.9 2007-08-16
岐阜県 多治見 40.9 2007-08-16
山形県 山形 40.8 1933-07-25
山梨県 甲府 40.7 2013-08-10
和歌山県 かつらぎ 40.6 1994-08-08
静岡県 天竜 40.6 1994-08-04
山梨県 勝沼 40.5 2013-08-10
埼玉県 越谷 40.4 2007-08-16
群馬県 館林 40.3 2007-08-16
群馬県 上里見 40.3 1998-07-04
愛知県 愛西 40.3 1994-08-05
千葉県 牛久 40.2 2004-07-20
静岡県 佐久間 40.2 2001-07-24
愛媛県 宇和島 40.2 1927-07-22
山形県 酒田 40.1 1978-08-03
岐阜県 美濃 40 2007-08-16
群馬県 前橋 40 2001-07-24
千葉県 茂原 39.9 2013-08-11
埼玉県 鳩山 39.9 1997-07-05
大阪府 豊中 39.9 1994-08-08
山梨県 大月 39.9 1990-07-19
山形県 鶴岡 39.9 1978-08-03
愛知県 名古屋 39.9 1942-08-02
'''
30 changes: 30 additions & 0 deletions kumbikumbiSIC/12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'''
1列目をcol1.txtに,2列目をcol2.txtに保存
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ.
参考 12.pyの答え  : https://qiita.com/segavvy/items/51a515c19bcd29b13b7f
参考 open()について : https://note.nkmk.me/python-file-io-open-with/
参考 明示的な改行 : https://www.glamenv-septzen.net/view/185
参考 ジェネレータについて(先頭の関数について) : https://qiita.com/tomotaka_ito/items/15b5999c76001dbc9a58
: https://qiita.com/tomotaka_ito/items/35f3eb108f587022fa09
'''

file_name = "hightemp.txt"

with open(file_name) as file, open("col1.txt", "w") as col1, \
open("col2.txt", "w") as col2:

lines = file.readlines();

for line in lines:
cols = line.split("\t")
col1.write(cols[0] + "\n")
col2.write(cols[1] + "\n")


'''
cut 参考url
http://x68000.q-e-d.net/~68user/unix/pickup?cut
'''
50 changes: 50 additions & 0 deletions kumbikumbiSIC/12_incomplete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'''
1列目をcol1.txtに,2列目をcol2.txtに保存
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ.
参考 12.pyの答え  : https://qiita.com/segavvy/items/51a515c19bcd29b13b7f
参考 open()について : https://note.nkmk.me/python-file-io-open-with/
参考 明示的な改行 : https://www.glamenv-septzen.net/view/185
参考 ジェネレータについて(先頭の関数について) : https://qiita.com/tomotaka_ito/items/15b5999c76001dbc9a58
: https://qiita.com/tomotaka_ito/items/35f3eb108f587022fa09
'''

class ReiteratableWrapper(object):
def __init__(self, f):
self._f = f

def __iter__(self):
return self._f()

file_name = "hightemp.txt"

with open(file_name) as file, open("col1.txt", "w") as col1, \
open("col2.txt", "w") as col2:

lines = file.read();
print(type(lines))

# lines = ReiteratableWrapper(lines)
# linesもう一度ループ文で使いたかった
# イテレータ、ジェンレータが原因か?

print('col1への書き込み')
for line in lines:
cols = line.split("\t")
#print(cols[0])
col1.write(cols[0] + "\n")

# 何も書き込まれない
print('col2への書き込み')
for line in lines:
cols = line.split("\t")
#print(cols[1])
col2.write(cols[1] + "\n")


'''
cut 参考url
http://x68000.q-e-d.net/~68user/unix/pickup?cut
'''
24 changes: 24 additions & 0 deletions kumbikumbiSIC/col1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
高知県
埼玉県
岐阜県
山形県
山梨県
和歌山県
静岡県
山梨県
埼玉県
群馬県
群馬県
愛知県
千葉県
静岡県
愛媛県
山形県
岐阜県
群馬県
千葉県
埼玉県
大阪府
山梨県
山形県
愛知県
24 changes: 24 additions & 0 deletions kumbikumbiSIC/col2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
江川崎
熊谷
多治見
山形
甲府
かつらぎ
天竜
勝沼
越谷
館林
上里見
愛西
牛久
佐久間
宇和島
酒田
美濃
前橋
茂原
鳩山
豊中
大月
鶴岡
名古屋
24 changes: 24 additions & 0 deletions kumbikumbiSIC/hightemp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
高知県 江川崎 41 2013-08-12
埼玉県 熊谷 40.9 2007-08-16
岐阜県 多治見 40.9 2007-08-16
山形県 山形 40.8 1933-07-25
山梨県 甲府 40.7 2013-08-10
和歌山県 かつらぎ 40.6 1994-08-08
静岡県 天竜 40.6 1994-08-04
山梨県 勝沼 40.5 2013-08-10
埼玉県 越谷 40.4 2007-08-16
群馬県 館林 40.3 2007-08-16
群馬県 上里見 40.3 1998-07-04
愛知県 愛西 40.3 1994-08-05
千葉県 牛久 40.2 2004-07-20
静岡県 佐久間 40.2 2001-07-24
愛媛県 宇和島 40.2 1927-07-22
山形県 酒田 40.1 1978-08-03
岐阜県 美濃 40 2007-08-16
群馬県 前橋 40 2001-07-24
千葉県 茂原 39.9 2013-08-11
埼玉県 鳩山 39.9 1997-07-05
大阪府 豊中 39.9 1994-08-08
山梨県 大月 39.9 1990-07-19
山形県 鶴岡 39.9 1978-08-03
愛知県 名古屋 39.9 1942-08-02

0 comments on commit aaf0f01

Please sign in to comment.