오늘의 마지막 질문 : test.txt 내에 있는 파일 이름에 대해서 출력해주기.

cs010101의 이미지

안녕하세요!!

test.txt 파일에,

aaa
bbb
ccc
ddd

라는 내용이 있으며 aaa,bbb,ccc,ddd 각각은 /etc/밑에 있는 파일을 가르킵니다.

이때, test.txt 파일에 적혀있는 이름의 파일을 읽어서 출력해줄려고 합니다.

즉, cat /etc/(test.txt 출력조작) 해서, /etc/aaa 라는 파일의 내용만(혹은 aaa,bbb,ccc,ddd 전부) 출력해줄려고 합니다.

어떻게 해야 할까요......

저는 이것을 sed를 이용해서 첫줄만(aaa만) 환경변수로 저장해서,

test='sed -n '1p' test.txt'
cat /etc/$test

하면 될 줄 알았는데, 않되네요.

조언해 주시면 감하겠습니다.

sh.의 이미지

cat /etc/`head -n 1 test.txt`
원하시는게 맞는지 잘 모르겠습니다

cs010101의 이미지

제가 리눅스 사용하는데,
알려주신대로 해봤더니,

>

이렇게 인풋이 나옵니당....

-----------------------------------------------
어머니,
그 이름만으로도 우리는 풍요로와 집니다.

효도합시다......
-----------------------------------------------

cinsk의 이미지

무난하게,

$ cat tmp.txt | while read f; do cat "/etc/$f"; done

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/

cs010101의 이미지

고맙습니다.

근데 sed, awk, grep 등등을 써서는 힘들까요?

-----------------------------------------------
어머니,
그 이름만으로도 우리는 풍요로와 집니다.

효도합시다......
-----------------------------------------------

sangwoo의 이미지

sed/awk/grep 필요 없이 저라면 이렇게 하겠습니다. cinsk님이랑 거의 같지만..

for i in `cat test.txt`; do
    cat /etc/$i
done

근데 아까 올리신 질문은 지우셨나봐요?
----
Let's shut up and code.

----
Let's shut up and code.

cs010101의 이미지

자체 해결했습니다.
오랜만에 쉘 만지다 보니까 깜깜해서 쉘바이블 펴놓고 뜻대로 되지 않네요.

여러모로 답변 해주신 분들 감사합니다.

-----------------------------------------------
어머니,
그 이름만으로도 우리는 풍요로와 집니다.

효도합시다......
-----------------------------------------------

sangwoo의 이미지

해결하셨다니 잘 되었습니다 ^^

아, 그리고 다른 사람이 비슷한 경우로 힘들어하게 될 경우를 대비해서
다음부터는 해결되더라도 원래 질문을 남겨두시길 부탁드립니다. :)

----
Let's shut up and code.

----
Let's shut up and code.

cs010101의 이미지

ㅎㅎ넹. 오키도키

-----------------------------------------------
어머니,
그 이름만으로도 우리는 풍요로와 집니다.

효도합시다......
-----------------------------------------------

송효진의 이미지

구글에서 "고급 bash" 로 검색해서 나오는 kldp 페이지를 추천합니다.

emerge money

cs010101의 이미지

질문하고 답변보고 책찾아보고 하는사이에 예전기억이 새록새록 나네요....

쉘프로그래밍이 젤로 재밌는거 같습니다.

-----------------------------------------------
어머니,
그 이름만으로도 우리는 풍요로와 집니다.

효도합시다......
-----------------------------------------------

MythRab의 이미지

awk '{print "/etc/" $1}' txt | xargs cat

Heading, heading again, again, ... ㅜㅜ 피난다

Heading, heading again, again, ... ㅜㅜ 피난다

MythRab의 이미지

awk '{print "/etc/" $1}' test.txt | xargs cat

Heading, heading again, again, ... ㅜㅜ 피난다

Heading, heading again, again, ... ㅜㅜ 피난다

댓글 달기

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