내가하면 grep -nr sumthin *
내 소스 코드 디렉토리에, 그것은 또한 축소 된 자바 스크립트 나 CSS 파일에서 매우 긴 줄을 결선. 한 줄에 처음 80자를 얻고 싶습니다.
예를 들어, 일반 grep
은 나에게 이것을 제공합니다 :
css/style.css:21: behavior: url("css/iepngfix.htc")
css/style-min.css:4:.arrow1{cursor:pointer;position:absolute;left:5px;bottom:10px;z-index:13;}.arrow2{cursor:pointer;position:absolute;right:5px;bottom:10px;z-index:13;}.calendarModule{z-index:100;}.calendarFooterContainer{height:25px;text-align:center;width:100%!important;z-index:15;position:relative;font-size:15px!important;padding:-2px 0 3px 0;clear:both!important;border-left:1px solid #CCC;border-right:1px ... etc.
하지만 대신 이것을 얻고 싶습니다.
css/style.css:21: behavior: url("css/iepngfix.htc")
css/style-min.css:4:.arrow1{cursor:pointer;position:absolute;left:5px;bottom:
어떤 리눅스 명령이 이것을 할 수 있습니까?
답변
세상에, 나는 완전히 잊었다 cut
!
grep -nr sumthin * | cut -c -80
^ 트릭을 수행합니다! > _ <
답변
cut
당신이 사용할 수있는 것 이외의 경우 fold
(및 경우에 따라 fmt
). 패키지의
fold
일부입니다 coreutils
.
$ echo "some very long long long text" | fold -w 5 # fold on 5 chars per line
some
very
long
long
long
text
fold
하지 않습니다 잘라 나머지 텍스트를하지만, 다음 줄에 출력.
답변
정확히 원하는 것은 아니지만 awk
특정 수의 열을 인쇄하는 데 사용할 수 있습니다 . 이 경우 구분자를 “:”로 지정할 수 있습니다.