리눅스 쉘스크립터로 파일내용 홀수줄 짝수줄 분할

how4565의 이미지


지금 student 파일에
1000 AAA
1001 BBB
1002 CCC
1003 DDD
1004 EEE
.
.
.
이렇게 구성되어있습니다
이걸 IFS 를 이용해서
1000
AAA
1001
BBB
1002
CCC
.
.
.
이런식으로 바꿔서 저장했습니다
이제 니걸 숫자따로 문자따로 즉
홀수열 짝수열로 나눌려고 하는데 방법좀 알려주세요 ㅠㅠ

익명 사용자의 이미지

그냥 원본 파일을 컬럼단위로 나누셈.
스페이스로 분리되어 있다면,

cut -f 1 -d ' ' student > num
cut -f 2 -d ' ' student > name

how4565의 이미지

cut 을 이용해서 할려구해봤는데실행하면 "구획문자는 단일 문자여야 합니다"라는 오류메세지가 계속떠서 이걸 해결하지 못하고있습니다 무엇때문인지 알수있을까요?

qiiiiiiiip의 이미지

어떻게 했는지 입력한 것과 출력된 것을 copy&paste해서
< code > < / code > 안에 넣어서 보여주세요~

$ cut -f 1 -d ' ' student
1000
1001
1002
1003
1004

$ cut -f 1 -d '  ' student
cut: 구획 문자는 단일 문자여야 합니다
Try 'cut --help' for more information.
how4565의 이미지

감사합니다
허나 제가 아직 cut을 배우지않아서
혹시 이런식으로 홀수줄 짝수줄 을
따로때서 저장하는 방법이있을꺼같은데
가능한가요????????/
------------------------------------
#!/bin/bash

IFS=$'\n'
for entry in `cat /home/han/student/`
do
IFS=' '
for value in $entry
do
echo "$value"
done

done > file

rem=$(( $n % 2 ))

if [ $rem -eq 0 ]
then
echo "$n is even number"
else
echo "$n is odd number"
fi
----------------------------
----------------------------

qiiiiiiiip의 이미지

굳이 어려운 길을 가시겠다면..

#!/bin/bash
IFS=$'\n'
n=0
for entry in `cat /home/han/student`
do
    IFS=' '
    for value in $entry
    do
        #echo "$value"
        if [ $(( n % 2 )) -eq 0 ]; then
            echo "$n is even"
        else
            echo "$n is odd"
        fi
        n=$((n+1))
    done
done
how4565의 이미지

감사합니다 덕분에 잘해결되었습니다 ^^

댓글 달기

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