2013-08-23 1 views

답변

1

어떻게 AWK에 대해? 입력이 input.txt를 저장하고, 위의 스크립트가 다음 명령을 원하는 출력 생성합니다, to_csv.sh라는 이름의 경우

#!/bin/bash 

awk ' 
BEGIN { 
    FS = ";"; # $1 will contain everything but the semicolon 
    first_item = 1; 
} { 
    if ($1 == "") { # handle empty line 
      printf "\n"; 
      first_item = 1; 
      next; 
    } 

    if (first_item != 1) { # avoid comma at the end of the line 
      printf ","; 
    } else { 
      first_item = 0; 
    } 

    printf "%s", $1; # print the item 
} END { 
    printf "\n"; 
}' 

:

./to_csv.sh < input.txt 
1

이 당신을 위해 작동 할 수 있습니다를 (GNU SED) :

sed -r ':a;$!N;s/;\n/,/;ta;s/,(\n)/\1/;$s/;//;P;D' file 

나이 :

sed -r ':a;$!N;s/;\n(timestamp)/\n\1/;s/;\n/,/;ta;s/,(\n)/\1/;$s/;//;P;D' file