
10개의 행이 있는 파일이 있습니다 1.txt
. 각 행을 순차적으로 전달 sed
하고 출력을 로그에 저장하고 싶습니다 .
job=`tail -1 1.txt`
getdd=`grep $job "mainlog.log"| sed -n '1p' $i > /tmp/result.log
답변1
귀하의 질문은 getdd
가치가 없기 때문에 쓸모없는 것 같습니다.
루프를 사용할 수 있습니다 while
.
while read -r job;
do
grep "$job" "mainlog.log"| sed -n '1p' "$i" >> /tmp/result.log
done < 1.txt
답변2
나는 xargs를 사용할 것이다
xargs -a 1.txt -I{} sh -c 'grep "$1" mainlog.log | head -n 1' _ {} > /tmp/result.log
또는 while 루프와 동일:
while IFS= read -r job; do
grep "$job" mainlog.log | head -n 1
done < 1.txt > /tmp/result.log