'쉘'에 해당되는 글 2건

  1. 2009.02.09 [UnixTip] 쉘에서의 산술 비교
  2. 2008.09.21 null copy

Unix 쉘에서의 산술 비교

Unix 쉘에서의 산술 비교는 정수값에 한정되어 있다. 다음은 기본적인
쉘 명령을 사용하여 부동 소수값을 비교하는 팁이다.

--------- CUT HERE-----------------
#! /bin/sh
# test shell script
n1="01.401"
n2="01.350"

function compareFloatSmall
{
sort -n <<: | head -1
$n1
$n2
:
}

function compareFloatGreat
{
sort -r -n <<: | head -1
$n1
$n2
:
}

small=$(compareFloatSmall $n1 $n2)
echo "Comparing $n1 to $n2: smaller $less"
great=$(compareFloatGreat $n1 $n2)
echo "Comparing $n1 to $n2: greater $great"
--------- CUT HERE-----------------

다른 방법으로 'awk' 프로그램을 사용할 수 있다.
--------- CUT AGAIN HERE-----------
#! /bin/sh
# A couple of examples in awk.
n1="03.550"
n2="02.550"

echo "$n1 $n2" | awk '{
       if ( $1 >= $2 ) print $1
       if ( $1 <= $2 ) print $2
       if ( $1 >  $2 ) print $1
       if ( $1 <  $2 ) print $2
       if ( $1 == $2 ) print $1, $2
}'
--------- CUT AGAIN HERE-----------

<><><><><><><><><><>원 문<><><><><><><><><><><>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 2926 - February  9, 2009

                   http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


ARITHMETIC COMPARISON

In UNIX shell arithmetic comparison
is limited to integer values.  Here
is a tip to compare floating values
using basic shell commands.

--------- CUT HERE-----------------

#! /bin/sh
# test shell script
n1="01.401"
n2="01.350"

function compareFloatSmall
{
sort -n <<: | head -1
$n1
$n2
:
}

function compareFloatGreat
{
sort -r -n <<: | head -1
$n1
$n2
:
}

small=$(compareFloatSmall $n1 $n2)
echo "Comparing $n1 to $n2: smaller $less"
great=$(compareFloatGreat $n1 $n2)
echo "Comparing $n1 to $n2: greater $great"

--------- CUT HERE-----------------

Alternatively you can use a small 'awk' program.

--------- CUT AGAIN HERE-----------
#! /bin/sh
# A couple of examples in awk.
n1="03.550"
n2="02.550"

echo "$n1 $n2" | awk '{
       if ( $1 >= $2 ) print $1
       if ( $1 <= $2 ) print $2
       if ( $1 >  $2 ) print $1
       if ( $1 <  $2 ) print $2
       if ( $1 == $2 ) print $1, $2
}'
--------- CUT AGAIN HERE-----------

반응형
Posted by She쥐포s

2008. 9. 21. 17:47 Unix/Shell

null copy

○ null copy
        File의 Size를 0으로 만드는 작업으로 일반적으로 로그파일이 커졌을 때 해당 파일의 사이즈를 초기화하는 목적
        등으로 사용됨.

○ 방법
        1. cat /dev/null > FILENAME
                 /dev/null 파일을 직접 파일에 Redirection한다.
                일반적인 경우 사용됨.
                 예)
                    # cat /dev/null > /var/log/messages

        2. > FILENAME
                직접 Redirection해서 파일에 쓴다.
                Bourne Shell, Korn Shell에서 사용됨
                예)

                    # > /var/log/messages


참고 원문
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                             UNIX GURU UNIVERSE
                                UNIX HOT TIP

                       Unix Tip 3151 - September 21, 2008

                   http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

NULL IT FAST

Here is the fastest way to truncate a file to zero
bytes in a bourne or korn shell.

$ > /var/log/messages

This is a good method, if the file has to be truncated,
but is opened by another process. For example, if you
want to truncate /var/log/messages, which is held
open by syslogd...

반응형
Posted by She쥐포s
이전버튼 1 이전버튼

블로그 이미지
She쥐포s
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함