1. 程式人生 > 其它 >shell小知識總結

shell小知識總結

技術標籤:研究生活shell語言程式碼小知識

1.查詢當前路徑下的檔案夾個數

ls -l|wc -l

2.遍歷資料夾下的檔案或資料夾

#這樣得到的是檔案的內容(原理基本上差不多)
path=`cat ${csvpath}`
for locations in $path
do
	echo $locations
done
#這樣得到的是當前路徑下的資料夾的名字
for file in `ls $locations`
do
	echo $file
done

其實這些還有其他寫法:知道就可以了。

#這樣得到的是檔案的內容(原理基本上差不多)
path=$(cat $csvpath)
for
locations in $path do echo $locations done

3.刪除某些行的操作

刪除指定行號的行

sed -i '2d' test_temp
刪除包含指bai定關鍵字的行:

sed -i '/hello/d' test_temp 
sed -i '1d' a.txt刪首行

sed -i '$d' b.txt刪尾行

sed -i ‘1,2d’a.txt刪2行

sed -i 's/[ ]*//g' c.txt刪空格

sed -i '/^$/d' d.txt刪空行

sed -i ‘/love/d’ a.txt刪包含string的行