From b6ab92ed76d067e3e5ad09d35e6483322b5efb93 Mon Sep 17 00:00:00 2001 From: Hikaru Morita Date: Thu, 28 Feb 2019 22:21:46 +0900 Subject: [PATCH 1/4] =?UTF-8?q?10=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kumbikumbiSIC/10.py | 83 ++++++++++++++++++++++++++++++++++++++ kumbikumbiSIC/hightemp.txt | 24 +++++++++++ 2 files changed, 107 insertions(+) create mode 100644 kumbikumbiSIC/hightemp.txt diff --git a/kumbikumbiSIC/10.py b/kumbikumbiSIC/10.py index e69de29..f3d1226 100644 --- a/kumbikumbiSIC/10.py +++ b/kumbikumbiSIC/10.py @@ -0,0 +1,83 @@ +以下コマンドラインのコピー + +~/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 character. Characters + beyond the final 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 , or 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 \ No newline at end of file diff --git a/kumbikumbiSIC/hightemp.txt b/kumbikumbiSIC/hightemp.txt new file mode 100644 index 0000000..7867f93 --- /dev/null +++ b/kumbikumbiSIC/hightemp.txt @@ -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 From 48b7d3e1fa543fe4d01ab5fc27451011153ed40c Mon Sep 17 00:00:00 2001 From: Hikaru Morita Date: Thu, 28 Feb 2019 22:32:31 +0900 Subject: [PATCH 2/4] =?UTF-8?q?11=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kumbikumbiSIC/11.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kumbikumbiSIC/11.py b/kumbikumbiSIC/11.py index e69de29..29f4a02 100644 --- a/kumbikumbiSIC/11.py +++ b/kumbikumbiSIC/11.py @@ -0,0 +1,27 @@ +以下コマンドラインのコピー + +~/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 \ No newline at end of file From 8d1bd1effed38745aae2e8425088eb38601a0b90 Mon Sep 17 00:00:00 2001 From: Hikaru Morita Date: Sat, 2 Mar 2019 00:55:31 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kumbikumbiSIC/04_pre.py | 54 ----------------------------------------- kumbikumbiSIC/09_sub.py | 0 kumbikumbiSIC/10.py | 16 +++++++++++- kumbikumbiSIC/11.py | 14 ++++++++++- 4 files changed, 28 insertions(+), 56 deletions(-) delete mode 100644 kumbikumbiSIC/04_pre.py delete mode 100644 kumbikumbiSIC/09_sub.py diff --git a/kumbikumbiSIC/04_pre.py b/kumbikumbiSIC/04_pre.py deleted file mode 100644 index 2029850..0000000 --- a/kumbikumbiSIC/04_pre.py +++ /dev/null @@ -1,54 +0,0 @@ -#マップ型の詳細 -#https://www.sejuku.net/blog/24759 -#高階関数 - -msg = "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can." -msg2 = msg.split() -msg3 = msg.split() - - -##単語ごとにリスト化 - -# 方法1: 配列はイテレータブルなのでforで要素を直接取り出せます。 -word = [] -for w in msg2: - word.append(w.replace(",", "").replace(".", "")) -#print("word:", word) - -# 方法2: インデックスをつけたい場合はenumerate()が使えます。 -for i, w in enumerate(msg2): - msg2[i] = w.replace(",", "").replace(".", "") -#print("msg2:", msg2) - -# 方法3: また、配列の全要素に同じ処理をするにはmap()が使えます。(戻り値がmapなのでlistにする必要があります) -msg3 = list(map(lambda word: word.replace(",", "").replace(".", ""), msg3)) -#print("msg3:", msg3) - -##上記の方法3つの出力が同じになる事を確認 - - -# 頭が悪いけど、これしか思いつかなかった -# スマートさに欠けている -# msg2[][]が分かりづらい -chars = [] -row = [] - -for i,w in enumerate(msg2): - if(i==0 or i==18 or i==14 or i==15): - chars.append(msg2[i][0]) - else: - chars.append(msg2[i][0] + msg2[i][1]) - #print(chars[i]) - row.append(i+1) - #print(row[i]) - -for i,w in enumerate(msg2[4:10]): - print(chars[i+4]) - chars[i+4] = msg2[i+4][0] - print(chars[i+4]) - -dic = dict(zip(chars,row)) -# 辞書型の出力の順番がグチャグチャ -print(dic) -#for char, num in dic.items(): -# print(char + ":" + str(num)) diff --git a/kumbikumbiSIC/09_sub.py b/kumbikumbiSIC/09_sub.py deleted file mode 100644 index e69de29..0000000 diff --git a/kumbikumbiSIC/10.py b/kumbikumbiSIC/10.py index f3d1226..e8038e5 100644 --- a/kumbikumbiSIC/10.py +++ b/kumbikumbiSIC/10.py @@ -1,3 +1,16 @@ +#行数をカウントせよ.確認には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 @@ -80,4 +93,5 @@ A wc command appeared in Version 1 AT&T UNIX. BSD February 23, 2005 BSD -~/s/1 \ No newline at end of file +~/s/1 +''' \ No newline at end of file diff --git a/kumbikumbiSIC/11.py b/kumbikumbiSIC/11.py index 29f4a02..4fc92cc 100644 --- a/kumbikumbiSIC/11.py +++ b/kumbikumbiSIC/11.py @@ -1,3 +1,14 @@ +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 @@ -24,4 +35,5 @@ 大阪府 豊中 39.9 1994-08-08 山梨県 大月 39.9 1990-07-19 山形県 鶴岡 39.9 1978-08-03 -愛知県 名古屋 39.9 1942-08-02 \ No newline at end of file +愛知県 名古屋 39.9 1942-08-02 +''' \ No newline at end of file From 5ec73980cbe94f932606b5c7dc4bece5a31e248b Mon Sep 17 00:00:00 2001 From: Hikaru Morita Date: Sat, 2 Mar 2019 22:39:03 +0900 Subject: [PATCH 4/4] =?UTF-8?q?12=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kumbikumbiSIC/12.py | 30 ++++++++++++++++++++ kumbikumbiSIC/12_incomplete.py | 50 ++++++++++++++++++++++++++++++++++ kumbikumbiSIC/col1.txt | 24 ++++++++++++++++ kumbikumbiSIC/col2.txt | 24 ++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 kumbikumbiSIC/12_incomplete.py create mode 100644 kumbikumbiSIC/col1.txt create mode 100644 kumbikumbiSIC/col2.txt diff --git a/kumbikumbiSIC/12.py b/kumbikumbiSIC/12.py index e69de29..4b246ea 100644 --- a/kumbikumbiSIC/12.py +++ b/kumbikumbiSIC/12.py @@ -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 + + +''' \ No newline at end of file diff --git a/kumbikumbiSIC/12_incomplete.py b/kumbikumbiSIC/12_incomplete.py new file mode 100644 index 0000000..778d3b3 --- /dev/null +++ b/kumbikumbiSIC/12_incomplete.py @@ -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 + + +''' \ No newline at end of file diff --git a/kumbikumbiSIC/col1.txt b/kumbikumbiSIC/col1.txt new file mode 100644 index 0000000..1ff11e8 --- /dev/null +++ b/kumbikumbiSIC/col1.txt @@ -0,0 +1,24 @@ +高知県 +埼玉県 +岐阜県 +山形県 +山梨県 +和歌山県 +静岡県 +山梨県 +埼玉県 +群馬県 +群馬県 +愛知県 +千葉県 +静岡県 +愛媛県 +山形県 +岐阜県 +群馬県 +千葉県 +埼玉県 +大阪府 +山梨県 +山形県 +愛知県 diff --git a/kumbikumbiSIC/col2.txt b/kumbikumbiSIC/col2.txt new file mode 100644 index 0000000..612ac3a --- /dev/null +++ b/kumbikumbiSIC/col2.txt @@ -0,0 +1,24 @@ +江川崎 +熊谷 +多治見 +山形 +甲府 +かつらぎ +天竜 +勝沼 +越谷 +館林 +上里見 +愛西 +牛久 +佐久間 +宇和島 +酒田 +美濃 +前橋 +茂原 +鳩山 +豊中 +大月 +鶴岡 +名古屋