首页 > 解决方案 > 在多个文件上运行命令

问题描述

我的脚本(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

我假设“日期”来自错误,这不是我要求的,第二列有我要求的值之一,但我仍然想念其他值。

标签: bash

解决方案


它以这种方式工作

for file 
in /dir./*.s01

do
   input=$file

推荐阅读