ex)
ls | grep hello
ls : 현재 디렉토리의 파일 출력
grep hello : hello 파일명을 가진 파일 출력
ps aux | grep httpd | aws '{print $2}'
ps aux : 프로세스 리스트를 출력
grep httpd : httpd 프로세스를 잡는다.
aws '{print $2}' : 해당 row의 2번째 열을 출력
ex)
grep "apple" fruits.txt
fruits.txt 파일에서 apple 문자열을 찾음
grep -r apple
현재 디렉토리로부터 apple 문자열 가지고 있는 파일을 찾음
grep -E "appl(e|es)" fruits.txt
fruits.txt 파일에서 "apple"이나 "apples" 문자열 찾음
ex)
fruits.txt
apple
orange
melon
apples
Apple
입력 -> wc fruits.txt
결과 -> 5(행) 5(단어) 32(문자) fruits.txt(파일명)
입력 -> echo "hello world" | wc
결과 -> 1(행) 2(단어) 12(문자)
💬 head
💬 tail
💬 diff
ex)
file : t1.txt
hello
hello world25
world
---
file : t2.txt
hello
hello world25
wrwr
rr
diff -u t1.txt t2.txt
--- t1.txt 2024-12-06 01:47:37.564972621 +0000
+++ t2.txt 2024-12-06 01:47:51.032822226 +0000
@@ -1,3 +1,4 @@
hello
hello world25
-world
+wrwr
+rr
💬 cmp
cmp t1.txt t2.txt
결과 : t1.txt t2.txt differ: byte 22, line 3
cmp -b t1.txt t2.txt
결과 : t1.txt t2.txt differ: byte 22, line 3 is 157 o 162 r
column base text mainpulation
ex)
awk '{print $1, $3}' file1.txt
file1.txt 파일의 첫 번째, 세 번째 컬럼($1, $3) 확인
awk '{sum += $2} END {print sum}' file1.txt
file1.txt 파일의 두 번째 컬럼을 모두 더한 후 출력한다.
awk '$2 > 20' file1.txt
file1.txt 파일의 두 번째 컬럼이 20보다 큰 행을 출력
awk '$2 > 20 {print $0}' file1.txt > temp.txt && mv temp.txt file1.txt
file1.txt 파일에서 두 번째 컬럼이 20보다 큰 행을 temp.txt로 입력 한 다음에 temp.txt를 file1.txt로 이동한다.(덮어쓴다.)