내 스크립트
#!/bin/bash
for file in *.xml; do
find . -name "*.xml" -exec grep "sample_freq" "{}" \;
find . -name "*.xml" -exec grep "sensor_sernum" "{}" \;
done
폴더용으로 딱이네요
<sample_freq>131072</sample_freq>
<sample_freq>131072</sample_freq>
<sample_freq>131072</sample_freq>
<sample_freq>131072</sample_freq>
<sample_freq>131072</sample_freq>
<sensor_sernum>0</sensor_sernum>
<sensor_sernum>0</sensor_sernum>
<sensor_sernum>255</sensor_sernum>
<sensor_sernum>237</sensor_sernum>
하지만 문제는 내 디렉터리에 7개의 폴더가 있고 각 폴더에 xml 파일이 있다는 것입니다. 7개 폴더 모두에 들어가 각 폴더에서 정보를 얻도록 스크립트를 확장할 수 있습니까?
내 디렉토리의 내용 milenko@milenko-HP-Compaq-6830s:~/Documents/magnetotellurics/MT8$ ls EDI's meas_2015-06-29_19-18-28 meas_2015-06-29_19-26-
58 meas_2015-06-29_19-47-58 mys.sh n.sh
meas_2015-06-29_19-03-00 meas_2015-06-29_19-22-58 meas_2015-06-29_19-30-58 meas_2015-06-29_20-39-58
나는 초로바가 나에게 제안한 것을 시도했습니다
#!/bin/bash
for file in ./*; do
grep 'sample_freq' "$file"
grep 'sensor_sernum' "$file"
done
하지만
grep: ./EDI´s: Is a directory
grep: ./EDI´s: Is a directory
grep: ./meas_2015-06-29_19-03-00: Is a directory
grep: ./meas_2015-06-29_19-03-00: Is a directory
grep: ./meas_2015-06-29_19-18-28: Is a directory
grep: ./meas_2015-06-29_19-18-28: Is a directory
grep: ./meas_2015-06-29_19-22-58: Is a directory
grep: ./meas_2015-06-29_19-22-58: Is a directory
grep: ./meas_2015-06-29_19-26-58: Is a directory
grep: ./meas_2015-06-29_19-26-58: Is a directory
grep: ./meas_2015-06-29_19-30-58: Is a directory
grep: ./meas_2015-06-29_19-30-58: Is a directory
grep: ./meas_2015-06-29_19-47-58: Is a directory
grep: ./meas_2015-06-29_19-47-58: Is a directory
grep: ./meas_2015-06-29_20-39-58: Is a directory
grep: ./meas_2015-06-29_20-39-58: Is a directory
find . -name "*.xml" -exec grep "sample_freq" "{}" \;
grep 'sample_freq' "$file"
grep 'sensor_sernum' "$file"
grep 'sample_freq' "$file"
grep 'sensor_sernum' "$file"
답변1
for
전혀 루프할 필요가 없습니다.
find . -name "*.xml" -exec grep "sample_freq" "{}" \; -exec grep "sensor_sernum" "{}" \;
답변2
여기서는 필요하지 않습니다 find
. $file 변수를 사용하고 경로가 포함된 와일드카드를 확장하세요.
for file in folder*/*.xml ; do # */ fix SE highlighting bug
grep 'sample_freq' "$file"
grep 'sensor_sernum' "$file"
done