평범한 개발자 행복한 가족, 패밀리그램

개발/안드로이드

Windows echo date 문자 정리

패밀리그램 2016. 12. 4. 03:21

Windows Command line 에서 날짜를 출력하기 위해 Echo를 사용하면


LineFeed와 Newline 을 정리해야 하는 경우가 생긴다.


Perl 이나 기타 스크립트를 이용해서 문자열을 붙여서 사용해야 할 경우에 위와 같은 문제에 부딪 힌다.


LINUX의 경우는 정말 간단하지만 Windows는 간단하지 않다... 


방법을 찾지 못 해 Cygwin을 설치하여 Cygwin GNU util중 하나인


tr을 사용 하였다.. 


echo %date:~0%_%time:~0,2%%time:~3,2% | tr -d "\\r\\n[:space:]


TR에 대한 help를 첨부 한다




사용법: tr [<옵션>]... <집합1> [<집합2>]

Translate, squeeze, and/or delete characters from standard input,

writing to standard output.


  -c, -C, --complement    use the complement of SET1

  -d, --delete            delete characters in SET1, do not translate

  -s, --squeeze-repeats   replace each input sequence of a repeated character

                            that is listed in SET1 with a single occurrence

                            of that character

  -t, --truncate-set1     first truncate SET1 to length of SET2

      --help     이 도움말을 표시하고 끝냅니다

      --version  버전 정보를 출력하고 끝냅니다


SETs are specified as strings of characters.  Most represent themselves.

Interpreted sequences are:


  \NNN            8진수 값 NNN의 문자 (1개에서 3개의 8진수 숫자)

  \\              백슬래쉬

  \a              소리나는 BEL

  \b              백스페이스

  \f              폼피드

  \n              줄바꿈

  \r              리턴

  \t              수평 탭

  \v              수직 탭

  CHAR1-CHAR2     CHAR1에서 CHAR2까지의 (커지는 순서대로) 모든 문자

  [CHAR*]         <집합2>에서, <집합1>의 길이만큼 CHAR를 복사

  [CHAR*REPEAT]   CHAR의 REPEAT번 반복, REPEAT가 0으로 시작하면 8진수

  [:alnum:]       모든 문자 및 숫자

  [:alpha:]       모든 문자

  [:blank:]       모든 수평 공백문자들

  [:cntrl:]       모든 컨트롤 문자

  [:digit:]       모든 숫자

  [:graph:]       모든 표시 가능한 문자, 공백은 포함하지 않음

  [:lower:]       모든 소문자

  [:print:]       모든 표시 가능한 문자, 공백 포함

  [:punct:]       모든 문장 기호 문자

  [:space:]       모든 수평 및 수직 공백문자

  [:upper:]       모든 대문자

  [:xdigit:]      모든 16진수 숫자

  [=CHAR=]        CHAR와 동일한 모든 문자


Translation occurs if -d is not given and both SET1 and SET2 appear.

-t may be used only when translating.  SET2 is extended to length of

SET1 by repeating its last character as necessary.  Excess characters

of SET2 are ignored.  Only [:lower:] and [:upper:] are guaranteed to

expand in ascending order; used in SET2 while translating, they may

only be used in pairs to specify case conversion.  -s uses SET1 if not

translating nor deleting; else squeezing uses SET2 and occurs after

translation or deletion.


Report tr bugs to bug-coreutils@gnu.org

GNU coreutils home page: <http://www.gnu.org/software/coreutils/>

General help using GNU software: <http://www.gnu.org/gethelp/>

Report tr translation bugs to <http://translationproject.org/team/en_GB.html>

For complete documentation, run: info coreutils 'tr invocation'



반응형