筆記

 

  • 替換字符串: sed 's/book/books/g' file

 

  • 選各目錄下用例列表
#!/bin/sh

module=local_index
test="scripts\/$module\/"
test1=scripts/$module
ls -l $test1 | awk '{print $9}'|sed 1d > log1.log
sed "s/^/"$test"&/g" log1.log

  

【Linux】1. vi模式下"/"搜索,須要轉義的符號:shell

       /\$bash

       /\/工具

       /\~spa

       /\^.net

       /\.指針

 

1. 批量修改不一樣文件中的同一字符串code

sed -i "s/oldString/newString/g" `grep oldString -rl /path`blog

 

2. 各類變量類型佔用的內存空間進程

          存儲大小     例值     註釋ip

byte      1byte        3      字節

int       4bytes       3      整數

short     2bytes       3      短整數

long      8bytes       3      長整數

float     4bytes     1.2      單精度浮點數

double    8bytes     1.2      雙精度浮點數

char      2bytes     'a'      字符

boolean   1bit      true      布爾值

 

 3. Valgrind工具使用方法

http://blog.csdn.net/longbei9029/article/details/55252526?locationNum=3&fps=1

 

4. 判斷shell中的字符串是否爲數字: 

echo $test1| awk '{print($0~/^[-]?([0-9])+[.]?([0-9])+$/)?"number":"string"}'

 

5. bash shell 變量 數學運算

#!/bin/bash

test=`cat 0331.log | sed -n '3p'`
test1=`cat 0331.log | sed -n '2p'`
te=`echo "$test+$test1" | bc`;
echo "3DN tocal sum : $te";

 

 

 1 /*取得當前目錄下的文件個數*/ 
 2 
 3 
 4 #include <stdio.h> 
 5 #include <stdlib.h> 
 6 #include <errno.h> 
 7 #include <sys/wait.h> 
 8 #include <string.h>
 9 
10 #define MAXLINE 1024 
11 
12 int main() 
13 { 
14 
15     char result_buf[3], command[MAXLINE]; 
16     char buf[4];
17     int rc = 0; // 用於接收命令返回值 
18     FILE *fp; 
19 
20     /*將要執行的命令寫入buf*/ 
21     snprintf(command, sizeof(command), "cd ~/Linux_learn/ABC;cat test.txt"); 
22     //snprintf(command, sizeof(command), "ls ./ | wc -l"); 
23 
24     /*執行預先設定的命令,並讀出該命令的標準輸出*/ 
25     fp = popen(command, "r"); 
26     if(NULL == fp) 
27     { 
28         perror("popen執行失敗!"); 
29         exit(1); 
30     } 
31 
32     while(fgets(result_buf, sizeof(result_buf), fp) != NULL) 
33     { 
34         /*爲了下面輸出好看些,把命令返回的換行符去掉 */
35         if('\n' == result_buf[strlen(result_buf)-1]) 
36         { 
37             result_buf[strlen(result_buf)-1] = '\0'; 
38         } 
39         
40         //printf("命令【%s】 輸出【%s】\r\n", command, result_buf); 
41         buf[0] = result_buf[0];
42         printf("%s", &result_buf[0]); 
43         //printf("%s\n", &buf[0]); 
44     } 
45 
46     if(result_buf=="1.0\n")
47     {
48         printf("111111\n");
49     }
50     if(&result_buf[0]=="1.0")
51     {
52         printf("111111\n");
53     }
54     if(result_buf=="2.0")
55     {
56         printf("22222\n");
57     }
58     else
59     {
60         printf("33333\n");
61     }
62     
63 /*
64     rc = pclose(fp);   //等待命令執行完畢並關閉管道及文件指針
65     if(-1 == rc) 
66     { 
67         perror("關閉文件指針失敗"); 
68         exit(1); 
69     } 
70     else 
71     { 
72         //printf("命令【%s】子進程結束狀態【%d】命令返回值【%d】\r\n", command, rc, WEXITSTATUS(rc)); 
73         printf("\n"); 
74     } 
75 */    
76     return 0; 
77 }
相關文章
相關標籤/搜索