[완료]파일 합치기 (각 파일에서 3번째 줄부터 끝까지)

오류 메시지

There was an error processing your request.
yangsee의 이미지

동일 포맷의 파일을 합치려고 합니다.

파일설명: 헤더 2줄, 나머지는 레코드 라인

파일을 합칠 때 헤더 2줄만 넣고 각 파일의 레코드를 합치는 일을 해야 합니다.
파일마다 라인수가 틀립니다.

간단한 방법이 있으면 부탁드립니다. (cat, sed 등)

파일1:
version
header
1,1,1
2,2,2

파일2:
version
header
1,1,1
2,2,2

합친파일:
version
header
1,1,1
2,2,2
1,1,1
2,2,2

감사합니다.

formidea의 이미지

merge.sh 라는 파일에 아래 내용을 넣으시고,

awk 'BEGIN {line=0;} {if (line > 1) print;  line = line + 1; }' $2 > $2.tmp
cat $1 $2.tmp > $3
rm $2.tmp

아래와 같이 실행하시면, result 파일에 합친 결과가 들어갈 겁니다.

> merge.sh file1 file2 result
octaphial의 이미지

awk 대신에 tail도 작동하네요.

tail -n +3 $2 > $2.tmp

yangsee의 이미지

알려주신 방법으로는 파일명이 파일에 포함되어 생성됩니다.
이거 없앨 수 없을까요?

==> 파일명 <==

최종호의 이미지

tail -q -n +3 *.log

yangsee의 이미지

답변 감사합니다.
이 경우는 2개의 파일의 경우에는 가능합니다.
n개의 파일을 처리할 때는 안되네요.

aero의 이미지

a.log

header
version
111
222

b.log
header
version
333
444

c.log
header
version
555
666

이라면

perl one-liner

perl -ne 'print if !$c || $.>2; $.=0,$c++ if eof' *.log

결과

header
version
111
222
333
444
555
666
ymir의 이미지

헤더가 모두 동일하다면.. 그냥 빼버리고 나머지만 cat 로 붙여버려도...

$ cat f1
version
header
1,1,1
2,2,2
$ cat f2
version
header
3,3,3
4,4,4
$ cat f3
version
header
5,5,5
6,6,6
$ echo -e "header\nversion" > out && cat f? | egrep -v 'header|version' >> out
$ cat out
header
version
1,1,1
2,2,2
3,3,3
4,4,4
5,5,5
6,6,6

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

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

yangsee의 이미지

^^

mogin1의 이미지

참고 잘했습니다

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.