最近用了幾個(gè)命令沃于,記錄一下
sed -i "s/\(.*\).sh/\1,\0/g" filename //替換婉商,-i 表示直接修改文件
sed -i '1i#key,value,description' filename //在文件首行插入
awk '{match($0,/href="([^"]+)"[^\>]+>([^\<]+)/,a);print a[1]"\t"a[2]}'
sed '/baidu/d' baidu_list.txt #刪除包含baidu的行
match兩種用法:
普通用法
match(字符串,正則表達(dá)式)
內(nèi)置變量RSTART表示匹配開始的位置晶通,RLENGTH表示匹配的長度
如果匹配到了,返回匹配到的開始位置华望,否則返回0
$ awk 'BEGIN{start=match("Abc Ef Kig",/ [A-Z][a-z]+ /);print RSTART,RLENGTH}'
4 4建立數(shù)組(If array a is provided, a is cleared and then elements 1 through n are filled with the portions of s that match the corresponding
parenthesized subexpression in r. The 0'th element of a contains the portion of s matched by the entire regular
expression r. Subscripts a[n, "start"], and a[n, "length"] provide the starting index in the string and length
respectively, of each matching substring.)
echo "foooobazbarrrrr | gawk '{ match($0, /(fo+).+(bar*)/, arr) #匹配到的部分自動(dòng)賦值到arr中蕊蝗,下標(biāo)從1開始
print arr[1], arr[2]
print arr[1, "start"], arr[1, "length"] #二維數(shù)組arr[index,"start"]值=RSTART
print arr[2, "start"], arr[2, "length"] #二維數(shù)組arr[index,"length"]值=RLENGTH}'
foooo barrrrr
1 5
9 7
在vim中插入當(dāng)前打開文件名
Ctrl+r, 光標(biāo)會(huì)變?yōu)? “
然后鍵入%
即可插入當(dāng)前文件的名字