(1) ある日、yamaya さんという怖い方がこのツイートを投稿する。
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
## From: https://en.wikipedia.org/wiki/Dc_(computer_program) | |
## prime number | |
2p # A = 2; print A | |
3p # A = 3; print A | |
## スタックの先頭にある数とsqrt(処理中の数)を計算 | |
[ # func f-# (int n) int { | |
d # A = n(試す数) | |
l! # B = ! -- nと試し割りの割る数を用意 |
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
[響] 0:a [け] 1:a [!] 2:a [ユ] 3:a [ー] 4:a [フ] 5:a [ォ] 6:a [ニ] 7:a [ア] 8:a [ム] 9:a | |
0sc | |
[ | |
lc | |
lC+ | |
10%;an | |
lC | |
1+ | |
d | |
sC |
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
# https://unix.stackexchange.com/questions/205936/how-can-i-quickly-sum-all-numbers-in-a-file/205939 | |
perl -pe 's/\d*/$s+=$&/ge}{$_=$s' file | |
perl -F= -pe '$s+=$F[1]}{print $s' file | |
awk -F= '{sum+=$2};END{print sum}' |
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
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : Register records | |
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : --> POST https://api.example/v2/records http/1.1 | |
2017-05-09 20:53:27 INFO --- [thread-1] myapp.logic : response: <?xml version="1.0" encoding="UTF-8"?> | |
<root> | |
<records> | |
<record> | |
<id>A001</id> | |
<date>1990-01-04</date> | |
<status>0</status> | |
</record> |
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
sed '/response:/{:loop;N;/<\/root>/!b loop;s/\n//g}' app.log | \ | |
# 特定の時間帯のログだけをgrep | |
grep '^2017-05-09 20:5[0-9]' | \ | |
# あとはgrepなりsedなりawkなりで自由に抽出 | |
grep -oP '<record> *\K.*?(?= *</record>)' | sed 's/<\/[^>]*> *<[^>]*>/,/g;s/<[^>]*>//g' | |
# 同じディレクトリにapp.logを置いて実行 | |
# $ bash script.sh | |
# 出力結果: | |
# A001,1990-01-04,0 |
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
Q1: | |
<welcome.txt tr '\0' '*' | fold -w 70 | |
初っ端からひどい | |
Q2: | |
ls | perl -C -Mutf8 -nle 'printf "mv $_ ";$_ =~ tr/0-9/0-9/ ;$_ =~ tr/A-Z/A-Z/;$_ =~ m/([0-9]).*([A-Z])/; print " $1年$2組.doc"' | |
Q3: | |
echo 2018{01..12}{01..31}$'\n' | date -f- +'%Y%m%d' 2>/dev/null | grep -P '([2357].*){4}' |
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
-------------------- | |
bash 3.2.0 | |
-------------------- | |
~$ bash --version | |
GNU bash, version 3.2.0(1)-release (x86_64-unknown-linux-gnu) | |
Copyright (C) 2005 Free Software Foundation, Inc. | |
~$ [[ "hoge" =~ ho.. ]] && echo "${BASH_REMATCH[0]}" | |
hoge |
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
#!/bin/bash | |
# Try this script on the docker container. | |
# Tested on macoOS High Sierra + Ubuntu 18.04 docker container. | |
rm -f "$HOME"/work/* | |
tmux -S "$HOME"/work/sess new-session -d | |
printf "%s\\n" A B C D | while read -r f;do |
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
#!/bin/bash | |
ceiling () { | |
local divide="$1";shift | |
local by="$1" | |
printf "%s\\n" $(( ( divide + by - 1 ) / by )) | |
} | |
equalized_partition_nums () { | |
local number="$1";shift | |
local count="$1" |