programing tip

'less'명령을 사용하는 동안 Unix에서 특수 문자 표시

itbloger 2020. 11. 11. 08:10
반응형

'less'명령을 사용하는 동안 Unix에서 특수 문자 표시


'less'명령어를 사용하면서 특수 문자를 보는 방법을 알고 싶습니다. 예를 들어 특수 표기법으로 인쇄 할 수없는 문자를보고 싶습니다. 예를 들어 'vi'편집기에서 달러 '$'문자로 표시되는 줄 종료 문자를보기 위해 "set list on"을 사용합니다. 마찬가지로 'less'명령을 사용하여이 작업을 수행하고 싶습니다.

나는 유닉스를 덜 수동으로 언급했지만 아무 소용이 없었다.


less는 환경에서 LESS라는 변수가 있는지 확인합니다.

~ / .profile (.bash_rc 등) 중 하나에 LESS를 설정 한 다음 less명령 줄에서 실행할 때마다 LESS를 찾을 수 있습니다.

이것을 추가 해보세요

 export LESS="-CQaix4"

이것은 내가 사용하는 설정이며, 혼란을 줄 수있는 몇 가지 동작이 포함되어 있으므로 ...

의 도움말 기능에서이 모든 것이 무엇을 의미하는지 알 수 있습니다 less. 'h'키와 코를 누르거나 덜 실행하면됩니다.

편집하다

도움말을 보니 -r 옵션도 있음을 알았습니다.

-r  -R  ....  --raw-control-chars  --RAW-CONTROL-CHARS
                Output "raw" control characters.

나는 고양이가 귀하의 요구 사항에 가장 정확하게 일치 할 수 있다는 데 동의합니다.

 cat -vet file | less

각 줄 끝에 '$'를 추가하고 탭 문자를 시각적 '^ I'로 변환합니다.

 cat --help
   (edited)
    -e                       equivalent to -vE
    -E, --show-ends          display $ at end of each line
    -t                       equivalent to -vT
    -T, --show-tabs          display TAB characters as ^I
    -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB

이게 도움이 되길 바란다.


cat을 사용하면 출력을 더 적게 파이프 할 수 있습니다.

cat -e yourFile | less

이 발췌 부분은 의미 man cat설명합니다 -e.

   -e     equivalent to -vE

   -E, --show-ends
          display $ at end of each line

   -v, --show-nonprinting
          use ^ and M- notation, except for LFD and TAB

위해 less사용 -u디스플레이 캐리지 리턴에 ( ^M)와 백 스페이스 ( ^H) 또는 -U이전 및 탭 (보여주는 ^I예 :) :

$ awk 'BEGIN{print "foo\bbar\tbaz\r\n"}' | less -U 
foo^Hbar^Ibaz^M

(END)

-U스위치가 없으면 출력은 다음과 같습니다.

fobar   baz

(END)

man less기능에 대한 자세한 설명은를 참조하십시오 .


In the same spirit as https://stackoverflow.com/a/6943976/7154924:

cat -A

-A, --show-all
       equivalent to -vET
-v, --show-nonprinting
       use ^ and M- notation, except for LFD and TAB
-E, --show-ends
       display $ at end of each line
-T, --show-tabs
       display TAB characters as ^I

Alternatively, or at the same time, you can pipe to tr to substitute arbitrary characters to the desired ones for display, before piping to a pager like less if desired.


All special, nonprintable characters are displayed using ^ notation in less. However, line feed is actually printable (just make a new line), so not considered special, so you'll have problems replacing it. If you just want to see line endings, the easiest way might be

sed -e 's/$/$/' | less

참고URL : https://stackoverflow.com/questions/6943928/show-special-characters-in-unix-while-using-less-command

반응형