我創建一個腳本,從整個文件夾中的所有文件中讀取指定的值的問題bash腳本從整個文件夾的文件中讀取specifc值
我有很多的電子郵件目錄中的文件,我需要從每個文件中提取2個特定值。
之後,我必須把它們放入一個新的文件,它看起來像這樣:
--------------
To: value1
value2
--------------
這就是我想做的事,但我不知道如何創建腳本:
# I am putting the name of the files into a temp file
`ls -l | awk '{print $9 }' >tmpfile`
# use for the name of a file
`date=`date +"%T"
# The first specific value from file (phone number)
var1=`cat tmpfile | grep "To: 0" | awk '{print $2 }' | cut -b -10 `
# The second specific value from file(subject)
var2=cat file | grep Subject | awk '{print $2$3$4$5$6$7$8$9$10 }'
# Put the first value in a new file on the first row
echo "To: 4"$var1"" > sms-$date
# Put the second value in the same file on the second row
echo ""$var2"" >>sms-$date
.......
,並在目錄
我嘗試使用,而每個文件和功能做同樣的,但我無法完成的腳本
謝謝
有可能超過一個錯誤,但首先是'tmpfile'包含文件名列表,當你做'貓TMPFILE | grep「To:0」'''''''''''''''''''''''''''你可以按照你的設想搜索文件名, –
根本不需要tmpfile,只要執行'grep -h「到:0」*'。 –
另一個:'var2 = cat file | grep主題| awk'{print $ 2 $ 3 $ 4 $ 5 $ 6 $ 7 $ 8 $ 9 $ 10}''反引號不存在。另外我不明白'file'文件裏面有什麼? –