bash - 在多个文件上运行命令
问题描述
我的脚本(bash shell)从文件 *026.s01 中提取一些数字
input=${input_dir}/*026.s01
seq=` cat $input |awk 'NR>3{print substr($2,5,7)}' | sort -n | head -1`
first_sht=` cat $input | awk 'NR>3{print int($3)}' | head -1`
last_sht=` cat $input | awk 'NR>3{print int($3)}' | tail -1`
echo " $seq $first_sht last_sht" | awk '{printf("%6s%10s%9s\n",$1,$2,$3)}' >> dir_file_SEQ-$seq.txt.
如何在多个文件上执行此操作${input_dir}/*.s01
?
我尝试使用:
for file in ${input_dir}/*.s01
do
done
echo " $seq $sail_line $src_dir" | awk '{printf("%6s%10s%9s\n",$1,$2,$3)}' >> dir_file_SEQ-$seq.txt
但是我没有得到几个 dir_file_SEQ-???.txt 文件,我只有一个名为 dir_file_SEQ-.txt 的文件,其内容如下:
Date 229
Date 409
Date 589
Date 769
Date 949
Date 1129
我假设“日期”来自错误,这不是我要求的,第二列有我要求的值之一,但我仍然想念其他值。
解决方案
它以这种方式工作
for file
in /dir./*.s01
do
input=$file
推荐阅读
- c# - 如何在 Visual Studio 上的 Crystal Report 中消除此错误?[水晶报告][打开连接错误]
- ios - Firebase 身份验证自定义声明过期
- boto3 - 我在哪里可以找到某些 boto3 文档页面的源 rst?
- python - 重复迭代 numpy 数组的相同子集的最快方法
- cmd - 收到 cmd 错误,因为我的 Windows 用户名中有空格
- docker - 部署到 App Engine 失败并显示“步骤 #0:未找到该应用的 .deps.json 文件”
- gsm - 如何使用 GPRS 使用 GSM 模块 (SIM900A) 向服务器发送 GET 请求
- graphviz - 使用 Graphviz 排序转换布局
- amazon-web-services - AWS EC2 IP 属于虚拟机还是物理服务器?
- php - For循环发送错误的值-树枝