[완료] text parsing 에 대해서 도움이 필요합니다.

fjoker의 이미지

안녕하세요

===============================
[aaaa] <== 편의상 제목
내용 블라블라~
내용 블라블라~
내용 블라블라~
내용 블라블라~

[bbbb]
내용 블라블라~
내용 블라블라~

[cccc]
내용 블라블라~
내용 블라블라~
내용 블라블라~

.
.
.
================================

이런형식의 text중에서

[bbbb]
내용 블라블라~
내용 블라블라~

이렇게 한부분만 보고 싶을때 어떻게 해야될지 도움을 부탁드립니다.

fact. 제목부분은 [main] 이런식으로 줄의 앞부분이 [ 로 시작하고 ]로 끝납니다.
fact. 내용부분의 줄의 앞부분에 한칸이상의 space가 들어갑니다. (게시판에 글쓰는데 앞에 스페이스부분은 먹어버리네요 --;)
fact. 내용부분의 길이는 얼마가 될지 모릅니다. (1 ~ 100).
fact. 내용이 끝나고 다음 제목이 오기전까진 new line 이 있습니다.

grep 을 이용해서 awk 등을 조금만 덧붙이면 될꺼 같기도 한데요 아 아무리 고민해도 힘드네요

cat test.txt | grep "^[bbbb" -A 100
으로 우선 원하는 부분부터 출력한뒤 두번째 [ 나오는시점에서 잘라내면 될꺼 같기도 한데..

많은 답변 부탁드립니다.
그럼 좋은하루되세요~

무한포옹의 이미지

$ awk -v flag=1 '{ if ($0 ~ /^[bbbb]/) flag*=-1; if ( $0 ~ /^\[[^\]]*\]/ ) flag *= -1 ;if  (flag>0) print $0  }' test.txt
[bbbb]
내용 블라블라~
내용 블라블라~

(뭐 되기는 됩니다)
-------------------------------
이건 뭐 익명도 아니고...

-------------------------------
== warning 대부분 틀린 얘기입니다 warning ===

무한포옹의 이미지

$ perl -ne 'print if m/^\[bbbb\]/i .. m/^\[[^b].*]/i' test.txt |head -n -1
[bbbb]
내용 블라블라~
내용 블라블라~

이런 것도 되긴 되는데....
-------------------------------
이건 뭐 익명도 아니고...

-------------------------------
== warning 대부분 틀린 얘기입니다 warning ===

jg의 이미지

주어진 조건이라면 sed 로는 아래와 같이 할 수 있겠네요.

sed -ne '/\[bbbb]/,/^$/p' text.txt | sed -n '$q; p'

$Myoungjin_JEON=@@=qw^rekcaH lreP rehtonA tsuJ^;$|++;{$i=$like=pop@@;unshift@@,$i;$~=18-length$i;print"\r[","~"x abs,(scalar reverse$i),"~"x($~-abs),"]"and select$good,$day,$mate,1/$~for 0..$~,-$~+1..-1;redo}

jg의 이미지

위의 것은 버그가... =_=;

sed -ne '/\[bbb]/,/^$/ { /^$/q; p } ' text.txt

$Myoungjin_JEON=@@=qw^rekcaH lreP rehtonA tsuJ^;$|++;{$i=$like=pop@@;unshift@@,$i;$~=18-length$i;print"\r[","~"x abs,(scalar reverse$i),"~"x($~-abs),"]"and select$good,$day,$mate,1/$~for 0..$~,-$~+1..-1;redo}

fjoker의 이미지

무한포옹님 jg님 정말 감사합니다~~~

제가 펄쪽은 많이 안친해서.. sed를 활용해서 해야겠네요

sed에서 /a/,/b/ 로 a에서부터 b까지만 볼수있군요, 그리고 /a/q 로 a에서부터 이하는 삭제할수도 있는거군요( 잘못 안건 아니겠지요. --;)

좋은거 많이 배웠습니다.~!!

두분다 건강하시고 부자되세요~~~~~~~

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.