2023年8月24日 星期四

AWK

1. 用","當作分隔,取出某一欄位
 cat *.csv | awk -V FS="," '{print $11}'

2. 比較某一欄的值是否大於或小於某個值
使用方法: cat *.txt | awk -f max.awk

BEGIN {
    max = 0.005;
    min = -0.005;
    FS="[,]";
    }
    {
if (FNR > 1) {
    if ($11>max) {
        # print NR;  -->印出行號
        print $0; -->印出該行內容
            }
    if ($11<min) {
        # print NR;
        print $0;
            }
}
}
END {
    printf("max = %f min = %f ", max,min);
} 

3. grep comparison results 
grep -A 2 Pass */*diff.cmp.txt | grep % | awk -F "|" '{print $5}' | xargs



2023年8月11日 星期五

vimdiff


摺疊的命令:
zo : open fold
zc : close fold
zr : reducing folding level
zm : more folding level
zR : reduce completel folding
zM : fold Most

重新計算diff :
:diffupdate or :diffu

同步滾動:
:set scrollbind
:set noscrollbind


2023年6月26日 星期一

Check spike current for CCST waveform

 #! /usr/local/bin/perl 

### input all simulation waveforms then export values which have spike current
### generate a shell script (check_waveform.sh) to plot waveforms in gnuplot for examination

open (AA, "ls analyze_ccs/*/*/*/waveforms/waveform simulation.txt |") or die;
    while (<AA>){
        chomp;
        push @libs, $_;
        }
close AA; 

$out = "check_waveform.sh";
open (BB,">$out") or die;
foreach $lib (@libs){
    open (AA, $lib) or die;
    #print "file: $lib ";
    $i=0; $previous_current=le-8; $present_current=le-8;
    #$dir=`basename $lib`;
    $dir=`dirname $lib`;
    chomp($dir);
    #print "dir path is $dir \n";
    while (<AA>){
        chomp;
        if ($i>"1"){
            @current=split(" ",$_);
            $present_current=$current[1];}
        if ($i=="2"){
            $previous_current=$current[1]; $present_current=$current[1];}
$rel_diff=abs($previous_current/$present_current) ;
#print "Rel diff is $rel_diff , previous is $previous_current , present is $present_current \n";
#export waveform values which have large differences (X10000)
        if ($rel_diff > 10000 || $rel_diff < 0.0001){
            print "file: $lib has spike at line $i, Rel diff is $rel_diff, previous is $previous_current, present is $present_current\n";
            $time_axis=$current[0]+le-10;
            print BB "sed -i '/set datafile missing/i";
            print BB "set xrange [0:$time_axis]";
            print BB "gnuplot $dir/gnuplot.cmd\n";
            print BB "gnuplot $dir/gnuplot.cmd\n";
            }
        $previous_current=$present_current ;
        $i++;
        }
close AA; 
}
close BB;

2022年2月12日 星期六

ETF實戰週記

 0050的進場時機

各位一定要先有兩個認知:
大盤日 K<20買K>80賣
空頭市場(大盤跌破季線超過一個月)大盤日 K<10買K>70賣

時間管理入門

 1.今天就開始您餘生的第一天。

2.時間管理是:控制自己的時間與工作,而不是讓它們控制自己
3.誰有清晰的目標,並追求它,也就能將他的潛能在實際行動上發揮出來(自我鼓勵與自我規律)。目標有助於將力量匯聚在眞正的重點上。問題不在於您作什麼事,而在您爲什麼做那些事情。設定目標是時間管理成功的先決條件與秘訣。
4.您必須嚴肅地把您的行事曆冊,您要
。設定優先順序
。化繁爲簡
。授權。
其餘的事必須順延、取消或加班處理。
5.如果一件事轉載記錄了很多次,將會造成困擾。這時有兩種可行性:
逮住它,現在就把它解決。
取消它,因爲已經没事了。
6.檢查《授權規則〉(快速分析法)
該作什麼?(內容)
誰該作?(人)
為什麼他該作?(動機,目標)
他該怎麼作?(範圍,細節)
什麼時候他該完成?(時限)

2021年9月1日 星期三

如何把變數帶入到sed內

foreach N (488 489 490 491 492 493 494 495) 

sed -i "$N s/^/#/g" test.tcl  --> 要用" " 不要用' ' ; $N後面要空格
                ^
liberate --trio test.tcl >& test.log
liberate --trio check.tcl >& check.log
mkdir Test$N ; mv test.log check.log TEST* Test$N ; rm -rf deck_TEST
end 


2021年4月27日 星期二

貪食蛇程式分析

 #include <iostream>

#include <string>

#include <stdlib.h>

#include <time.h>

using namespace std;


class Point{ // 與位置相關的類別

private: // 宣告私有資料成員

int x;

int y;

public: // 宣告公用資料成員

Point(int a,int b) // 宣告公用成員函數,有傳值時x=a,y=b沒有傳

{

x=a;

y=b;

}

Point() // 宣告公用成員函數,沒有傳值時x=0,y=0

{

x=0;

y=0;

}

void setPoint(int a,int b) // 設定x,y的位置函數

{

x=a;

y=b;

}

int getX() // 取得X方向的位置函數

{

return x;

}

int getY() // 取得y方向的位置函數

{

return y;

}

};


class SnakeGame{ // 與位置相關的類別

private:

char area[10][10]; //定義遊戲範圍為10X10的二維陣列 

Point head; //定義"頭"的資料型態為Point 

Point body[64]; //定義"身體" 

Point tail; //定義"尾巴" 

Point food; //定義"食物" 

int Length; //定義"長度"為整數

public:

SnakeGame()

{

Length=5;

// 設定蛇與食物的初始位置

head.setPoint(4,3);

body[0].setPoint(4,4);

body[1].setPoint(4,5);

body[2].setPoint(4,6);

body[3].setPoint(4,7);

tail.setPoint(4,7);

food.setPoint(4,1);

for(int i=0;i<10;i++) // 利用二維迴圈劃出遊戲範圍

{

for(int j=0;j<10;j++){

if(i==0||i==9||j==0||j==9)

area[i][j]='#';

else

area[i][j]=' ';

}

}

// 畫出蛇與食物位置

area[head.getX()][head.getY()]='O';

area[body[0].getX()][body[0].getY()]='O';

area[body[1].getX()][body[1].getY()]='O';

area[body[2].getX()][body[2].getY()]='O';

area[tail.getX()][tail.getY()]='O';

area[food.getX()][food.getY()]='*';

}

bool checkSpace(int step){ // 檢查蛇是否撞到牆壁或者回頭吃到自己的函數

if(step==76){  // 往左邊走一步,76是L的ascii碼

return !( area[head.getX() ][head.getY()-1]=='#'||area[head.getX()][head.getY()-1]=='O'); 

}

else if(step==85){ //往上面走一步,85是U的ascii碼 

return !(area[head.getX()-1][head.getY()]=='#'||area[head.getX()-1][head.getY()]=='O');

} 

else if(step==82){ //往右邊走一步,82是R的ascii碼 

return !(area[head.getX()][head.getY()+1]=='#'||area[head.getX()][head.getY()+1]=='O');

}

else if(step==68){ //往下面走一步,68是D的ascii碼 

return !(area[head.getX()+1][head.getY()]=='#'||area[head.getX()+1][head.getY()]=='O');

}

}

void run(int step){ // 蛇移動時的處理函數

tail.setPoint(body[Length-2].getX(),body[Length-2].getY());

int tempX=tail.getX();

int tempY=tail.getY();

area[tail.getX()][tail.getY()]=' '; // 蛇移動後用空白將尾巴消除

// 蛇移動後身體往前移動一格

for(int i =Length-1;i>0;i--)

{body[i].setPoint(body[i-1].getX(),body[i-1].getY());}

body[0].setPoint(head.getX(),head.getY());

// 蛇頭移動後的處理方式

if(step==76){  //蛇頭往左邊移動一格

head.setPoint(head.getX(),head.getY()-1);}

else if(step==85){//蛇頭往上面移動一格

head.setPoint(head.getX()-1,head.getY());}

else if(step==82){//蛇頭往右邊移動一格

head.setPoint(head.getX(),head.getY()+1);}

else if(step==68){//蛇頭往下面移動一格 

head.setPoint(head.getX()+1,head.getY());}

for(int i =0;i<Length-2;i++)

{area[body[i].getX()][body[i].getY()]='O';}

area[head.getX()][head.getY()]='O';

Eatfood(tempX,tempY);

}

void printArea(){ // 畫出10X10範圍內的圖像函數

for(int i=0;i<10;i++){

for(int j=0;j<10;j++)

{cout<<area[i][j];}

cout<<endl;

}

}

void Foodset() // 設定食物位置的函數

{

int foodX,foodY;

srand((unsigned)time(NULL));

            // 亂數產生新的食物

foodX=(rand()%8)+1;

foodY=(rand()%8)+1;

for(int i =0;i<Length-2;i++) // 檢查亂數產生新的食物是否跟蛇的身體重疊

{

if(foodX != body[i].getX() && foodY != body[i].getY())

{if((foodX != head.getX() && foodY != head.getY()) ||( foodX!=0 && foodY!=0) || (foodX != tail.getX() && foodY != tail.getY()))

{food.setPoint(foodX,foodY);}}

}

area[food.getX()][food.getY()]='*';

}

void Eatfood(int tempX,int tempY){ // 蛇吃到食物的處理函數

if(head.getX()==food.getX()&&head.getY()==food.getY()) // 判斷蛇有沒有吃到食物

{

Length++; // 蛇長度+1

body[Length-1].setPoint(tempX,tempY);

area[body[Length-1].getX()][body[Length-1].getY()]='O';

Foodset(); // 產生新的食物

} 

}

};


int main(int argc, char** argv) { // 主程式

SnakeGame sg;

char step;

while(1)

{

sg.printArea(); 

cout<<"請輸入移動方向(U/D/L/R):";

cin>>step;

if(step==76||step==85||step==82||step==68)

{

if(sg.checkSpace(step)) // 檢查蛇移動後是否違反規則

{sg.run(step); // 蛇移動

}

else{ // 蛇是撞到牆壁或者回頭吃到自己則結束程式

cout<<"GameOver"<<endl; 

break;}

} 

system("cls");

}

return 0;

}

標籤