2021年2月19日金曜日

ゼロサプレス zero supress bash awk split 文字列分割

 bash

$ seq -f %03g 1 10

001
002
003
004
005
006
007
008
009
010


ループ  loop

for i in `seq -f %03g 1 90`; do wget https://blog-imgs-77-origin.fc2.com/u/r/u/urutoraerogazou/matsushima-kaede-166-$i.jpg ; done


for i in `seq 414 453`; do wget  https://blog-imgs-76-origin.fc2.com/d/e/n/densetsuav/1543tachibanarikopin-$i.jpg ; done


二重ループ double loop サンプル

for j in `seq 1 34`
    do for i in `seq 1 12`
      # do wget -r https://javtube.com/javpic/ameri-ichinose/$j/ameri-ichinose-$i.jpg
      do wget -r https://jjgirls.com/japanese/rin-aikawa/$j/rin-aikawa-$i.jpg
  done
done




R


 for(i in seq(1,47,1)){ colnames(mdf)[i] <-  (paste(sprintf("%02d",i),colnames(mdf)[i],sep=""))}


sprintf("%.2f",100.0111)

[1] "100.01"

sprintf("%.3f",100.0111)

[1] "100.011"

sprintf("%.5f",100.0111)

[1] "100.01110"

sprintf("%.6f",100.0111)

[1] "100.011100"



awk


awk '{$3=sprintf("%02d", $3);


find . -print | awk -F\. '{print $2}' | grep k | awk -F\/ '{print $3"-"$2}' | awk '{split($0,a,"-"); print "cp \.\/"a[4]"\/"a[1]"-"a[2]"-"a[3]".jpg  ~\/tmpimage\/kaede\/jjgirls.com\/"a[1]a[2]a[4]"-"a[3]".jpg"}' > kaedecp.txt


split($0,a,"-")で行全体を-で区切って分割する。分割した各要素はa[i]でアクセスできる。

2021年2月16日火曜日

append new entries to xts object.

 

last(tmp.predict,3)

        SP5.Open SP5.High  SP5.Low SP5.Close   SP5.Volume   spline      eps
10 2020 3385.870 3549.850 3233.940  3269.960  89737600000 3475.842 3450.187
11 2020 3296.200 3645.990 3279.740  3621.630 100977880000 3465.431 3396.378
12 2020 3645.870 3760.200 3633.400  3756.070  96056410000 3420.055 3238.727


create the entry for "2021-01-01". first to create single row matrix and convert to the xts.

as.xts(matrix(c(as.vector(apply.monthly(SP5["2021-01"],mean)),3395,3180),nrow=1),as.Date("2021-01-01"))[,-5]

                    [,1]          [,2]            [,3]             [,4]       [,5]                 [,6]    [,7]
2021-01-01 3797.387 3818.136 3768.962 3793.748 5555199474 3395 3180


run append.

append(tmp.predict,as.xts(matrix(c(as.vector(apply.monthly(SP5["2021-01"],mean)),3395,3180),nrow=1),as.Date("2021-01-01"))[,-5]) %>% last(.,6)

        SP5.Open SP5.High  SP5.Low SP5.Close   SP5.Volume   spline      eps
 8 2020 3288.260 3514.770 3284.530  3500.310  84402300000 3270.029 3340.749
 9 2020 3507.440 3588.110 3209.450  3363.000  92084120000 3416.319 3423.604
10 2020 3385.870 3549.850 3233.940  3269.960  89737600000 3475.842 3450.187
11 2020 3296.200 3645.990 3279.740  3621.630 100977880000 3465.431 3396.378
12 2020 3645.870 3760.200 3633.400  3756.070  96056410000 3420.055 3238.727
 1 2021 3797.387 3818.136 3768.962  3793.748   5555199474 3395.000 3180.000


2021年2月5日金曜日

EPS 2021FEB05

 


eps_year_xts["2020::"]

             [,1]

2020-01-01 116.33
2020-04-01  99.23
2020-07-01  96.47
2020-10-01  92.18
2021-01-01 106.60
2021-04-01 125.68
2021-07-01 132.68
2021-10-01 140.24

$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'

eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.23
eps_year_xts["2019::"][7] <- 98.22
eps_year_xts["2019::"][8] <- 96.45
eps_year_xts["2019::"][9] <- 119.73
eps_year_xts["2019::"][10] <- 139.51
eps_year_xts["2019::"][11] <- 146.75
eps_year_xts["2019::"][12] <- 154.78

2020年12月25日金曜日

R 4.0 ggplot

scale_fill_hue(name='regions',labels= as.character(unique(w[,5])) )

ラベルの使用順序はscale で明示すること。これがないとalphabeticalにソートされてしまう。

上記だけをやると列名とラベルが不整合を起こすので、列名にも数字を先頭に付加してソート順序を制御しなくてはならない。


  for(i in seq(1,47,1)){ colnames(mdf)[i] <-  (paste(sprintf("%02d",i),colnames(mdf)[i],sep=""))}


reshape2はもう使えない。したがってmelt() も使えない。

melt(data=mdf, id.vars="t", measure.vars=as.character(unique(w[,5]))) は

  df.melt <- mdf  %>% tidyr::gather(variable,value,as.character(colnames(mdf)[-48]))

になる。

以下をインストールしておくこと。

  • tidyr                                Tidy Messy Data
  • dplyr                                A Grammar of Data Manipulation


unloadするときは。

detach("package:dplyr", unload=TRUE)
detach("package:tidyr", unload=TRUE)



2020年11月14日土曜日

EPS 2020NOV14

 > eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01  99.23
2020-07-01  93.03
2020-10-01  87.16
2021-01-01 101.75
2021-04-01 119.53
2021-07-01 128.19
2021-10-01 135.75


$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'

eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.23
eps_year_xts["2019::"][7] <- 96.47
eps_year_xts["2019::"][8] <- 92.18
eps_year_xts["2019::"][9] <- 106.60
eps_year_xts["2019::"][10] <- 125.68
eps_year_xts["2019::"][11] <- 132.68
eps_year_xts["2019::"][12] <- 140.24

2020年10月25日日曜日

EPS 2020OCT25

 


>   eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01  99.16
2020-07-01  93.44
2020-10-01  89.68
2021-01-01 110.65
2021-04-01 129.66
2021-07-01 139.84
2021-10-01 148.29

$   tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'

eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.23
eps_year_xts["2019::"][7] <- 93.03
eps_year_xts["2019::"][8] <- 87.16
eps_year_xts["2019::"][9] <- 101.75
eps_year_xts["2019::"][10] <- 119.53
eps_year_xts["2019::"][11] <- 128.19
eps_year_xts["2019::"][12] <- 135.75


for reference

$    cat eps.txt 

12/31/2021 $44.69 $37.23 21.02 25.44 $164.30 $135.75
9/30/2021 $42.32 $36.45 22.20 26.94 $155.59 $128.19
6/30/2021 $40.10 $35.60 23.54 28.89 $146.68 $119.53
3/31/2021 $37.19 $26.47 25.89 33.94 $133.37 $101.75
12/31/2020 $35.98 $29.66 29.85 39.62 $115.68 $87.16
9/30/2020 (25.0%) 3363.00 $33.41 $27.79 29.05 37.12 $118.88 $93.03
6/30/2020 3100.29 $26.79 $17.83 24.75 31.24 $125.28 $99.23
3/31/2020 2584.59 $19.50 $11.88 18.64 22.22 $138.63 $116.33
12/31/2019 3230.78 $39.18 $35.53 20.56 23.16 $157.12 $139.47
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40 $152.97 $132.90
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27
3/31/2019 2834.40 $37.99 $35.02 18.52 21.09 $153.05 $134.39

2020年10月9日金曜日

awk tr sed mondate CLI download

1. download cli from this url 

1.1 change downloaded file name to CLI3.csv

1.2 ~/R/R2/index/cli_download.sed  run at the terminal.


sed -n '/USA/p' CLI3.csv |awk -F, '{print $6"-01,"$7}'  |sed 's/\"//g' |awk 'BEGIN{print "DATE,DATA"}{print $0}' > usa.csv

# extract OECD entries and exclude OECDE

sed -n '/OECD[^E]/p' CLI3.csv |awk -F, '{print $6"-01,"$7}'  |sed 's/\"//g' |awk 'BEGIN{print "DATE,DATA"}{print $0}' > oecd.csv

# 

sed -n '/CHN/p' CLI3.csv |awk -F, '{print $6"-01,"$7}'  |sed 's/\"//g' |awk 'BEGIN{print "DATE,DATA"}{print $0}' > chn.csv

# 

sed -n '/EA19/p' CLI3.csv |awk -F, '{print $6"-01,"$7}'  |sed 's/\"//g' |awk 'BEGIN{print "DATE,DATA"}{print $0}' > ea19.csv

#

sed -n '/JPN/p' CLI3.csv |awk -F, '{print $6"-01,"$7}'  |sed 's/\"//g' |awk 'BEGIN{print "DATE,DATA"}{print $0}' > jpn.csv



1.3 run cli_load.r in R.


2.when cli is downloaded form this url 


2.1. do as below in terminal change FILE_NAME accordingly.

grep "OECD - Total" <FILE_NAME>.csv  | grep LOLITOAA |gawk -F, 'BEGIN{print "c("}{print $(NF-2)","}END{print ")  " }' | tr -d "\n" | sed 's/,)/)/'


output is like 


c(100.1448,100.0088,99.88226,99.7745,99.68903,99.62392,99.56622,99.5041,99.44289,99.39536,99.37106,99.38042,99.41794,99.46317,99.49193,99.47968,99.41767,97.69222,93.17708,94.81512,97.03869,98.08919,98.53291,98.79954) 


> length(c(100.1448,100.0088,99.88226,99.7745,99.68903,99.62392,99.56622,99.5041,99.44289,99.39536,99.37106,99.38042,99.41794,99.46317,99.49193,99.47968,99.41767,97.69222,93.17708,94.81512,97.03869,98.08919,98.53291,98.79954) )

[1] 24


# start and end dates are fixed. caution!

seq( as.Date(mondate(Sys.Date())-24)-day(mondate(Sys.Date()))+1,as.Date(mondate(Sys.Date())-1),by='months' )


>seq( as.Date(mondate(Sys.Date())-24)-day(mondate(Sys.Date()))+1,as.Date(mondate(Sys.Date())-1),by='months' )

 [1] "2018-10-01" "2018-11-01" "2018-12-01" "2019-01-01" "2019-02-01" "2019-03-01" "2019-04-01" "2019-05-01" "2019-06-01"

[10] "2019-07-01" "2019-08-01" "2019-09-01" "2019-10-01" "2019-11-01" "2019-12-01" "2020-01-01" "2020-02-01" "2020-03-01"

[19] "2020-04-01" "2020-05-01" "2020-06-01" "2020-07-01" "2020-08-01" "2020-09-01"

 

2.2. do as below in R

as.xts(c(100.1448,100.0088,99.88226,99.7745,99.68903,99.62392,99.56622,99.5041,99.44289,99.39536,99.37106,99.38042,99.41794,99.46317,99.49193,99.47968,99.41767,97.69222,93.17708,94.81512,97.03869,98.08919,98.53291,98.79954), seq( as.Date(mondate(Sys.Date())-24)-day(mondate(Sys.Date()))+1,as.Date(mondate(Sys.Date())-1),by='months' ))


2.3. alternatively do as below 

grep "OECD - Total" <FILE_NAME>.csv  | grep LOLITOAA |gawk -F, 'BEGIN{print "as.xts(c("}{print $(NF-2)","}END{print "), seq( as.Date(mondate(Sys.Date())-24)-day(mondate(Sys.Date()))+1,as.Date(mondate(Sys.Date())-1),by=\"months\" ))  " }' | tr -d "\n" | sed 's/,)/)/'



2020年10月4日日曜日

mac addr DHCP LAN

 


  • 58:E2:8F:22:5F:C0       iphone se
  • F8:4E:73:02:B7:6C      (iPhone11onomoto) via br0 ?
  • 34:A8:EB:81:58:4A       ipad mini
  • F8:FF:C2:65:B5:0C       macbook pro 16inch
  • 78:4F:43:98:2F:8C       macbook pro 15inch
  • 00:1E:C2:A7:D3:EB      macbook kuro
  • 18:C2:BF:16:51:90      LS5110 NAS  wired LAN
  • 82:BA:85:04:AB:ED      iphone 11 pro
  • 74:75:48:1E:CD:4F       kindle  from mac address
  • 00:F7:6F:CF:4E:E6 airmac express
  • 58:55:CA:30:E6:4C      apple tv
  • 50:c4:dd:e9:70:b0        router

身元不明macアドレス
  • 192.168.11.102        74:75:48:1E:CD:4F       31:15:20        kindle 
  • 192.168.11.110 72:8C:56:0F:7B:73

2020年10月3日土曜日

bash for and while

 

全てのcsvを0 length にする。

for i in *.csv ; do  cat /dev/null >  $i; done


無限ループ。「while : (コロン)」で無限ループになる。

$  while : ; do echo 'hello'; sleep 10 ; done

2020年9月1日火曜日

行列の計算 matrix()

 

> 1:15
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

> matrix(1:15,ncol=3)
     [,1] [,2] [,3]
[1,]    1    6   11
[2,]    2    7   12
[3,]    3    8   13
[4,]    4    9   14
[5,]    5   10   15

> diff(matrix(1:15,ncol=3))
     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    1    1    1
[4,]    1    1    1


> c(1:7,NA,9:15)
 [1]  1  2  3  4  5  6  7 NA  9 10 11 12 13 14 15
> w <- matrix(c(1:7,NA,9:15), ncol=5)
> w
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5   NA   11   14
[3,]    3    6    9   12   15

> v <- as.vector(w)
> v[is.na(v)]
[1] NA
> v[is.na(v)] <- 8
> matrix(v,ncol=dim(w)[2])
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15
> w <- matrix(v,ncol=dim(w)[2])
> w
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15

EPS 2020SEP01

 


> eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01 100.29
2020-07-01  94.83
2020-10-01  92.54
2021-01-01 112.31
2021-04-01 128.51
2021-07-01 138.90
2021-10-01 146.96


$  tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.16
eps_year_xts["2019::"][7] <- 93.44
eps_year_xts["2019::"][8] <- 89.68
eps_year_xts["2019::"][9] <- 110.65
eps_year_xts["2019::"][10] <- 129.66
eps_year_xts["2019::"][11] <- 139.84
eps_year_xts["2019::"][12] <- 148.29

2020年8月16日日曜日

plot3d color col=

 


Don't forget "col="  in the parameters. it's not scatterplot3d!!


library(rgl)

len <- dim(mdf)[1]

x3d <- c()

for(i in seq(1,47,1)){ x3d <- append(x3d,rep(i,len))}

z3d <- c()

for(i in seq(1,47,1)){ z3d <- append(z3d,dmdf[,i])}

y3d <- as.integer(gsub('-','',as.character(dmdf$t)))

# aichi 23, osaka 27, fukuoka 40, tokyo 13.

# color <- c(rep("grey",12*len),rep("orange",len),rep("grey",9*len),rep("pink",len),rep("grey",3*len),rep("yellow",len),rep("grey",12*len),rep("green",len),rep("grey",6*len),rep("red",len))

par(bg = 'grey25', fg = 'white',col.axis = 'white',col.lab='white')

y3d <- seq(1,len,1)

# plot3d(x3d,rep(y3d,47),z3d,col = color, type = "h", pch = " ",zlim=c(0, max(dmdf[,-48])))

plot3d(x3d,rep(y3d,47),z3d,col = as.vector(matrix(rep(rainbow(47),len),ncol=47,byrow=t)), type = "h", pch = " ",zlim=c(0, max(dmdf[,-48])))




==


2020年8月11日火曜日

scatterplot3d

 use same data.frame mdf as the previous entry.


library("scatterplot3d")

len <- dim(mdf)[1]

x3d <- c()

for(i in seq(1,47,1)){ x3d <- append(x3d,rep(i,len))}

z3d <- c()

for(i in seq(1,47,1)){ z3d <- append(z3d,mdf[,i])}

# scatterplot3d(x3d,rep(mdf$t,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,500))

y3d <- as.integer(gsub('-','',as.character(mdf$t)))

# scatterplot3d(x3d,rep(y3d,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,500))

color <- c(rep("black",12*len),rep("orange",len),rep("black",13*len),rep("yellow",len),rep("black",12*len),rep("green",len),rep("black",7*len))

# scatterplot3d(x3d,rep(y3d,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,30),angle = 65)

scatterplot3d(x3d,rep(y3d,47),z3d,color, type = "h", pch = " ",zlim=c(0, max(mdf[,-48])),angle = 65,col.grid="grey")



color <- c(rep("grey",12*len),rep("orange",len),rep("grey",13*len),rep("yellow",len),rep("grey",12*len),rep("green",len),rep("grey",7*len))
par(bg = 'grey25', fg = 'white',col.axis = 'white',col.lab='white')
scatterplot3d(x3d,rep(y3d,47),z3d,color, type = "h", pch = " ",zlim=c(0, max(mdf[,-48])),angle = 65)


2020年8月10日月曜日

scatterplot3d

when mdf is like below

head(mdf,2)

  Hokkaido Aomori Iwate Miyagi Akita Yamagata Fukushima Ibaraki Tochigi Gunma Saitama Chiba Tokyo Kanagawa Niigata Toyama

1       10      0     0      0     0        0         0       0       0     0       6     2     2        0       3      0

2        8      0     0      0     0        0         0       0       0     2       3     2     2        3       0      0

  Ishikawa Fukui Yamanashi Nagano Gifu Shizuoka Aichi Mie Shiga Kyoto Osaka Hyogo Nara Wakayama Tottori Shimane Okayama

1        0     0         0      0    0        1     7   5     0     2     9     8    0        0       0       0       0

2        0     0         0      0    0        0     3   0     0     0     3    13    0        0       0       0       0

  Hiroshima Yamaguchi Tokushima Kagawa Ehime Kochi Fukuoka Saga Nagasaki Kumamoto Oita Miyazaki Kagoshima Okinawa

1         0         0         0      0     0     0       0    0        0        0    0        0         0       0

2         0         0         0      0     0     0       0    1        0        0    0        0         0       0

           t

1 2020-03-12

2 2020-03-13


do as below

library("scatterplot3d")

len <- dim(mdf)[1]

x3d <- c()

for(i in seq(1,47,1)){ x3d <- append(x3d,rep(i,len))}

z3d <- c()

for(i in seq(1,47,1)){ z3d <- append(z3d,mdf[,i])}

# scatterplot3d(x3d,rep(mdf$t,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,500))

y3d <- as.integer(gsub('-','',as.character(mdf$t)))

# scatterplot3d(x3d,rep(y3d,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,500))

scatterplot3d(x3d,rep(y3d,47),z3d,highlight.3d = TRUE, type = "h", pch = " ",zlim=c(0,500),angle = 65)