lecture/기본 개념 및 명령어

awk, sed,

infra 2021. 11. 5. 01:50

ll 명령어를 통해 기준으로 출력된 값은 다음과 같다.

 

root@ubuntu16:/tmp/sort_test# ll
total 32
drwxr-xr-x  5 root root 4096 11월  5 01:28 ./
drwxrwxrwt 13 root root 4096 11월  5 01:27 ../
-rw-r--r--  1 root root    0 11월  5 01:28 dir.txt
drwxr-xr-x  2 root root 4096 11월  5 01:12 sor/
-rw-r--r--  1 root root   18 11월  5 01:12 sort
-rw-r--r--  1 root root    9 11월  5 00:54 sort_test2
-rw-r--r--  1 root root   50 11월  4 22:29 sort_testfile
drwxr-xr-x  2 root root 4096 11월  5 00:58 sortt/
drwxr-xr-x  3 root root 4096 11월  5 00:59 sorttt/

 

 

 

 

좌측 그림을 기준으로 보면 $1 첫번째 column만 출력하는걸로 awk명령어를 수행했다.

우측 그림의 명령어는 9번째 column 과 5번째 column을 순서대로 출력하는 명령어이다.

 

 

 

 

root@ubuntu16:/tmp/sort_test# ll |awk '{sum+=$5} END{print sum}'
20557

=> 5번째 컬럼을 모두 더해서 출력하라는 의미이다.

 

 

root@ubuntu16:/tmp/sort_test# ll |sed 's/[a-z]/\U&/g'
TOTAL 32
DRWXR-XR-X  5 ROOT ROOT 4096 11월  5 01:45 ./
DRWXRWXRWT 13 ROOT ROOT 4096 11월  5 01:27 ../
-RW-R--R--  1 ROOT ROOT    0 11월  5 01:45 =
-RW-R--R--  1 ROOT ROOT    0 11월  5 01:28 DIR.TXT
DRWXR-XR-X  2 ROOT ROOT 4096 11월  5 01:12 SOR/
-RW-R--R--  1 ROOT ROOT   18 11월  5 01:12 SORT
-RW-R--R--  1 ROOT ROOT    9 11월  5 00:54 SORT_TEST2
-RW-R--R--  1 ROOT ROOT   50 11월  4 22:29 SORT_TESTFILE
DRWXR-XR-X  2 ROOT ROOT 4096 11월  5 00:58 SORTT/
DRWXR-XR-X  3 ROOT ROOT 4096 11월  5 00:59 SORTTT/

 

 

좌측

 

root@ubuntu16:~# cd /usr/share/doc/vim/
root@ubuntu16:/usr/share/doc/vim# cat copyright |grep book
Any publication in standard (paper) book form shall require the citation of the
all outer surfaces of the book. On all outer surfaces of the book the original
part in standard (paper) book form for commercial purposes is prohibited unless
the work in any standard (paper) book form is prohibited unless prior

 

 

우측

 

root@ubuntu16:/usr/share/doc/vim# cat /usr/share/doc/vim/copyright |ss/book/leesh/g' > mycopyright

 

>로 mycopyright 라는 파일을 자동으로 만들어

book을 leesh 로 변경하고 나머지는 다 복사하는 걸로 만들었다.

 

 

 


root@ubuntu16:/usr/share/doc/vim# diff /usr/share/doc/vim/copyright mycopyright
123c123
< Any publication in standard (paper) book form shall require the citation of the
---
> Any publication in standard (paper) leesh form shall require the citation of the
125c125
< all outer surfaces of the book . On all outer surfaces of the book the original
---
> all outer surfaces of the leesh. On all outer surfaces of the leesh the original
207c207
< part in standard (paper)book  form for commercial purposes is prohibited unless
---
> part in standard (paper)leesh form for commercial purposes is prohibited unless
211c211
< the work in any standard (paper) book  form is prohibited unless prior
---

> the work in any standard (paper) leesh form is prohibited unless pr
ro

diff 명령어로 A 와 B를 비교해서 해당 바뀐 줄을 각줄로 표시된다.

'lecture > 기본 개념 및 명령어' 카테고리의 다른 글

grep, sort  (0) 2021.11.04