![awk에서 공백이 있는 파일 이름을 입력하는 방법](https://linux55.com/image/183547/awk%EC%97%90%EC%84%9C%20%EA%B3%B5%EB%B0%B1%EC%9D%B4%20%EC%9E%88%EB%8A%94%20%ED%8C%8C%EC%9D%BC%20%EC%9D%B4%EB%A6%84%EC%9D%84%20%EC%9E%85%EB%A0%A5%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
test.sh
내가 넣은 bash 파일에
#!/bin/bash
dirpath="/home/dir"
myfile="$dirpath/file with white space"
awk '{print "firstcolumn"$1":"$4,$2}' ${myfile}.bim >file2
스크립트를 실행하면 sh test.sh
오류 메시지가 나타납니다
awk: fatal: cannot open file '/home/dir/file' for reading (No such file or directory)
. 공백이 있는 파일을 처리하려면 awk를 어떻게 얻나요?
나는 또한 file\ with\white\ space를 시도했지만 작동하지 않습니다.
답변1
인용한 다른 맥락과 정확히 동일합니다.
awk '{print "firstcolumn"$1":"$4,$2}' "${myfile}.bim" >file2
이렇게 하면 전역 문자가 포함된 파일 이름도 방지됩니다.myfile="$dirpath/*"