![매개변수로 사용할 파일 내용을 전달하는 방법은 무엇입니까? [폐쇄]](https://linux55.com/image/146478/%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98%EB%A1%9C%20%EC%82%AC%EC%9A%A9%ED%95%A0%20%ED%8C%8C%EC%9D%BC%20%EB%82%B4%EC%9A%A9%EC%9D%84%20%EC%A0%84%EB%8B%AC%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%ED%8F%90%EC%87%84%5D.png)
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