반응형

흠...


어느날 갑자기...

Jennifer으로 떨어진 profile.txt 파일에서

특정 구문만을 분석할 일이 발생했따...

즉,

많이 호출되는 PKG의 ARGUMENT의 내용을 검색하고 싶어졌다

후후... 한 시간동안 대충 만든거라 수정이 필요하지만.

기록상 남겨둔다

예를들면...

stringAnalyzer.sh PKG_NUM.ALL profile.txt D 5

profile.txt 파일에서  PKG_NUM.ALL을 호출한 패키지의 아래의 5줄 사이에 param으로 뿌려진 결과를 출력함.

#!/bin/ksh

##############################################################################################################
#
# 문자열 분석 쉘
#
# 용도 : 제니퍼 로그에서 특정 구문의 호출되는 인자값을 찾기 위한 용도 (반복 패턴 및 호출되는 형태 분석을 위해)
#
#
#
#
##############################################################################################################


if [ $# -eq 0 ]; then
        echo ""
        echo "문자열 분석 쉘"
        echo "=================================================="
        echo "$0 FindText TargetFile Position Number "
        echo "=> FindText   : 찾으려는 문구를 입력함"
        echo "=> TargetFile : 대상 파일"
        echo "=> Position   : D(아래쪽)"
        echo "=> Number     : 아래의 몇줄 안에 param 구문 모두 출력"
        echo ""

else
  

        # 1. 해당 Argument 별로 유효한지 먼저 체크 필요
        # echo abc | tr "[a-z]" "[A-Z]" (대문자 변경  출력)


        # 1. 검색하려는 문자가 들어있는 열을 출력함.
        FindTxt=`grep -n $1 $2 | awk '{print $1}' | sed 's/://g'`

        # 2. 상향인지 하향인지 구분 변수
        UpDown=`echo $3 | tr "[a-z]" "[A-Z]"`

        echo "$2 File"
        echo "==============================="
        echo "File Text : $1"
        echo "======================================================================"
        echo ""
        for i in $FindTxt
        do
                #       echo "i : " $i
                #echo $UpDown
                GetRow=$i
                if [ $UpDown = "U" ]; then
                        GetRow=`expr $i - $4`
                elif [ $UpDown = "D" ]; then
                        GetRow=`expr $i + $4`
                else
                        GetRow=`expr $i`
                fi;

                j=0
                while [ $j -le $4 ]
                do
                        GetRow=`expr $i + $j`
                        ExistRow=`head -$GetRow $2 | tail -1 | grep param2: | grep -v grep | wc -l`

                        if [ $ExistRow -ne 0 ]; then
                                ViewRow=`head -$GetRow $2 | tail -1`
                                echo "$ViewRow"
                        fi;

                        j=`expr $j + 1`
                done
        done
fi

반응형

'Language' 카테고리의 다른 글

npm node module 공통 관리하기  (0) 2020.10.28
Inter-process communication  (0) 2014.03.27
우리은행 웹 접근성 가이드 주소  (0) 2011.08.09
빠른 수식 계산법  (0) 2010.03.01
반응형

흠흠흠...

문자열 변환 함수 translate

뭐 쉽게 얘길하면

TRANSLATE("문자열", "찾을집합","변경집합")으로 변환가능.

중요한 것은 찾을 집합에 없는 값은 무조건 그냥 출력한다는 것이다.

ex) SELECT TRANSLATE('ABC-1234-5678', 'abc1234','def5678') FROM DUAL;

즉, 'ABC-1234-5678'에서 찾는 집합 'abc1234'에 매핑되는 값만 'def5678'로 변경된다.

위의 문자열중 매핑 안되는 값은 그냥 출력된다.

매핑 안되는 문자열값 : ABC-5678 이 값들은 찾을 집합에 존재하지 않으므로 그냥 skip하여 출력되며

찾는 집합 변경 집합 
 a
 b
 c
 1
 2 6
 3 7
 4 8

위의 표를 기준으로 볼때 a가 발견되면 d로 변경된다.

아래의 값에서 ABC-는 찾는집합과 변경집합이 없으므로 skip 되며

나머지 값들은 모두 해당 변경 집합으로 변경되어 출력된다.

결과
---------------
ABC-5678-5678

TRANSLATE (string1, search_set, replace_set)

Replaces every instance in string1 of a character from search_set with the corresponding character from replace_set. For example:

    TRANSLATE ('abcd', 'ab', '12') --> '12cd'

If the search set contains more characters than the replace set, then the "trailing" search characters that have no match in the replace set are not included in the result. For example:

    TRANSLATE ('abcdefg', 'abcd', 'zyx') --> 'zyxefg'

The letter 'd' is removed, because it appears in search_set without a corresponding entry in result_set.


TRANSLATE(text USING CHAR_CS) and TRANSLATE(text USING NCHAR_CS)

Translates character data to either the database character set (CHAR_CS) or the national character set (NCHAR_CS). The output datatype will be either VARCHAR2 or NVARCHAR2, depending on whether you are converting to the database or the national character set, respectively.

TRANSLATE...USING is an ISO standard SQL function. Starting with Oracle9i Database Release 1, you can simply assign a VARCHAR2 to an NVARCHAR2, (and vice versa), and Oracle will handle the conversion implicitly. If you want to make such a conversion explicit, you can use TO_CHAR and TO_NCHAR to convert text to database and national character sets, respectively. Oracle recommends the use of TO_CHAR and TO_NCHAR over TRANSLATE...USING, because those functions support a greater range of input datatypes.


출처 : 영어부분은 Oracle PL/SQL Programming 책에서 발췌...
반응형

+ Recent posts