我有一个Matlab程序将一些数据输出到文件名中,例如文件名看起来像
Temperature_10_Volumn_5.dat
该文件内部为空,但我需要解析出10和5。我有1000个这样的文件。解析数字并将其写入csv文件以使Matlab可以读取csv文件并绘制图形的最简单的shellscript是什么?谢谢!
这是将所有值打印在一个文件中的脚本,其中值之间用“;”分隔
用法是:
parse_file.sh /home/user/your_dir_to_files output.csv
#!/bin/bash
#title :parse_file.sh
#description :parse file name into a single file
#author :Bertrand Martel
#date :13/08/2015
file_list=`ls $1`
IFS=$'\n' #line delimiter
#empty your output file
cp /dev/null "$2"
for i in $file_list; do
#get temperature between _ and _
temperature=`echo $i | awk -v FS="([_]|[_])" '{print $2}'`
#remove everything before Volumn
second_part=`echo $i | sed 's/.*Volumn//'`
#get volume between _ and .
volume=`echo $second_part | awk -v FS="([_]|[.])" '{print $2}'`
new_line="$temperature;$volume"
#append to file
echo $new_line >> "$2"
done
cat "$2"
我使用文件https://gist.github.com/akinaru/fd68c0373af35eaba934创建了要点
我假设您的目录输出中只有所谓的文件
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句