awk, grep, sed 함께 사용

exitys66의 이미지

안녕하세요 .반갑습니다.

쉬운 내용일 수도 있는데 제가 초보라 그런지 도저히 이해가 안가네요.
조금만 도와주세요.

1. 아래와 같은 txt 문서를 csv 문서로 바꾸고 싶습니다.

"test7.c", line 1.1: 1506-224 (I) Incorrect pragma ignored.
"test7.c", line 3.8: 1506-450 (I) Obsolete non-prototype-style function declaration.
"test7.c", line 3.26: 1506-944 (I) Attribute "xyz" is not supported and is ignored.
"test7.c", line 4.6: 1506-450 (I) Obsolete non-prototype-style function declaration.
"test7.c", line 6.1: 1506-166 (S) Definition of function class requires parentheses.

2. awk, sed, grep를 이용해서 변경하고 싶어요

3. 아래의 예시 처럼 6개 정도의 필드로 나누고 싶습니다.

ex) "test7.c", // line // 6.1: // 1506-166 // (S) // Definition of function class requires parentheses

4. 혹시 이 작업이 명령어 한번으로 해결이 가능할까요?

도와주세요.

ymir의 이미지

$ cat in.txt
"test7.c", line 1.1: 1506-224 (I) Incorrect pragma ignored.
"test7.c", line 3.8: 1506-450 (I) Obsolete non-prototype-style function declaration.
"test7.c", line 3.26: 1506-944 (I) Attribute "xyz" is not supported and is ignored.
"test7.c", line 4.6: 1506-450 (I) Obsolete non-prototype-style function declaration.
"test7.c", line 6.1: 1506-166 (S) Definition of function class requires parentheses.
$ cat in.txt | sed 's/,//g' | while read -r line; do set -a $line; echo -n "$1,$2,$3,$4,$5,"; shift 5; echo $*; done
"test7.c",line,1.1:,1506-224,(I),Incorrect pragma ignored.
"test7.c",line,3.8:,1506-450,(I),Obsolete non-prototype-style function declaration.
"test7.c",line,3.26:,1506-944,(I),Attribute "xyz" is not supported and is ignored.
"test7.c",line,4.6:,1506-450,(I),Obsolete non-prototype-style function declaration.
"test7.c",line,6.1:,1506-166,(S),Definition of function class requires parentheses.
$ cat in.txt | sed 's/,//g' | awk 'BEGIN {OFS=","; ORS=""} {print $1,$2,$3,$4,$5","; sub(".*"$6,$6); print $0"\n"}'
"test7.c",line,1.1:,1506-224,(I),Incorrect pragma ignored.
"test7.c",line,3.8:,1506-450,(I),Obsolete non-prototype-style function declaration.
"test7.c",line,3.26:,1506-944,(I),Attribute "xyz" is not supported and is ignored.
"test7.c",line,4.6:,1506-450,(I),Obsolete non-prototype-style function declaration.
"test7.c",line,6.1:,1506-166,(S),Definition of function class requires parentheses.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』