-k num[.offset1, num.offset2][OPTS]
option | description |
---|---|
b | ignore leading blanks |
d | dictionary order |
f | ignore case |
g | general numeric sort |
i | ignore nonprinting character |
M | month sort : 'JAN' < 'FEB' < ... < 'DEC' |
h | human numeric sort |
n | numeric sort |
R | random sort |
r | reverse |
V | version sort |
jsg@jsg-ubuntu:~$ ls -l | sort -k 7n -k5nr 합계 56 -rw-r--r-- 1 jsg jsg 8980 12월 8 22:52 examples.desktop drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Desktop drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Documents drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Downloads drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Music drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Public drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Templates drwxr-xr-x 2 jsg jsg 4096 12월 10 20:22 Videos drwxr-xr-x 3 jsg jsg 4096 12월 20 00:24 snap drwxr-xr-x 2 jsg jsg 4096 12월 21 23:49 Pictures drwxrwxr-x 6 jsg jsg 4096 12월 23 02:06 xycar_ws -rwxrwxr-x 1 jsg jsg 23 12월 31 12:17 test.sh
jsg@jsg-ubuntu:~$ cat sort.txt jim,27,US park,31,KOR xing,14,CHN jsg@jsg-ubuntu:~$ sort -t, -k2 sort.txt xing,14,CHN jim,27,US park,31,KOR
jsg@jsg-ubuntu:~$ cat unique.txt user1 user2 user4 user3 user2 user1 jsg@jsg-ubuntu:~$ sort -u unique.txt user1 user2 user3 user4
파일을 나누는 명령어
split [options] file [prefix]
option | description |
---|---|
-d | 영문자 suffix 대신 숫자 suffix 사용 |
-a len | suffix 길이 지정 |
-b size | 용량 단위로 나눔 |
-C size | 행단위로 최대 size만큼 나눔 |
-l num | 행 수 단위로 나눔 |
jsg@jsg-ubuntu:~$ split -d -a 5 -l 10000 /usr/share/dict/words word jsg@jsg-ubuntu:~$ wc -l word* 10000 word00000 10000 word00001 10000 word00002 10000 word00003 10000 word00004 10000 word00005 10000 word00006 10000 word00007 10000 word00008 9171 word00009 99171 합계
jsg@jsg-ubuntu:~$ head -5 /usr/share/dict/words A A's AA's AB's ABM's jsg@jsg-ubuntu:~$ tail -5 /usr/share/dict/words épée's épées étude étude's études
jsg@jsg-ubuntu:~$ paste -d ':' <(ls) <(stat -c %a *) Desktop:755 Documents:755 Downloads:755 Music:755 Pictures:755 Public:755 Templates:755 Videos:755 examples.desktop:644 paste.txt:664 snap:755 test.sh:775 xycar_ws:775
jsg@jsg-ubuntu:~$ pr examples.desktop 2020-12-08 22:52 examples.desktop 1 페이지 [Desktop Entry] Version=1.0 Type=Link Name=Examples Name[aa]=Ceelallo Name[ace]=Contoh Name[af]=Voorbeelde Name[am]=ምሳሌዎች ...
공통키를 가지는 필드를 기준으로 병합
-filenum fieldnum
: 키 필드 지정
-o "filenum.fieldnum ..."
: 출력 형식
jsg@jsg-ubuntu:~$ cat join1.txt user1 jsg vip user2 ksh gold user3 lhj silver jsg@jsg-ubuntu:~$ cat join2.txt 27 user2 2019-10-08 32 user3 2020-01-04 19 user3 unknown 21 user5 2018-08-19 jsg@jsg-ubuntu:~$ join -1 1 -2 2 -o "0 1.2 2.3 2.1" join1.txt join2.txt user2 ksh 2019-10-08 27 user3 lhj 2020-01-04 32 user3 lhj unknown 19
일부부만 선택해서 출력
-d : delimeter
-f : 필드
jsg@jsg-ubuntu:~$ cat cut.txt http://naver.com http://korea.org http://nexon.co.kr jsg@jsg-ubuntu:~$ cut -d "/" -f 3 cut.txt naver.com korea.org nexon.co.kr jsg@jsg-ubuntu:~$ cut -d "." -f 2,3 cut.txt com org co.kr jsg@jsg-ubuntu:~$ cut -d "." -f 2-3 cut.txt com org co.kr
{ } 의 외부 버전
-s : seperator
-w : 0으로 길이를 맞춰줌
jsg@jsg-ubuntu:~$ seq -w -s "/" 1 10 01/02/03/04/05/06/07/08/09/10
option | description |
---|---|
-d delimeter | delimeter (default : newline) |
-n num | 지정된 크기만큼 읽음 |
-a arr | 배열로 지정 |
-u fd | fd로부터 읽음 |
jsg@jsg-ubuntu:~$ read var1 var2 <<HERE
>> 11 22
>> HERE
jsg@jsg-ubuntu:~$ echo $var1; echo $var2
11
22
jsg@jsg-ubuntu:~$ ps PID TTY TIME CMD 100757 pts/1 00:00:00 bash 100819 pts/1 00:00:00 ps jsg@jsg-ubuntu:~$ exec /bin/sh $ ps PID TTY TIME CMD 100757 pts/1 00:00:00 sh 100820 pts/1 00:00:00 ps
jsg@jsg-ubuntu:~$ cat exec.sh exec 3<$1 # open input file for reading. exec 4>$2 # open output file for writing. while : ; do in_string=$(head -1 <&3) if [ ! "$in_string" ]; then exit fi echo "---" >&4 echo "$in_string" >&4 done
jsg@jsg-ubuntu:~$ cat oldfile.txt Alpha Bravo Charlie jsg@jsg-ubuntu:~$ bash exec.sh oldfile.txt newfile.txt jsg@jsg-ubuntu:~$ cat newfile.txt --- Alpha --- Bravo --- Charlie
jsg@jsg-ubuntu:~$ cat exec.sh #! /bin/bash declare -i cnt=0 exec 4< <(ps hu) while read -a f_array <&4 ; do echo "$cnt : PID(${f_array[1]}) ID(${f_array[0]}) (${f_array[@]:10})" let cnt++ done echo "cnt = $cnt" jsg@jsg-ubuntu:~$ ./exec.sh 0 : PID(100757) ID(jsg) (/bin/bash) 1 : PID(101041) ID(jsg) (/bin/bash ./exec.sh) 2 : PID(101042) ID(jsg) (/bin/bash ./exec.sh) 3 : PID(101043) ID(jsg) (ps hu) cnt = 4
jsg@jsg-ubuntu:~$ cat eval.sh #! /bin/bash pf_1=Hello; pf_2=world; pf_3=linuxer var_prefix="pf" for i in 1 2 3 do eval "echo $i = \$${var_prefix}_${i}" done jsg@jsg-ubuntu:~$ bash eval.sh 1 = Hello 2 = world 3 = linuxer
jsg@jsg-ubuntu:~$ cat eval.sh #! /bin/bash echo "export var=12" jsg@jsg-ubuntu:~$ eval '$(bash eval.sh)' jsg@jsg-ubuntu:~$ echo $var 12
jsg@jsg-ubuntu:~$ printf "%03d - %.3f (%-20s)\n" 27 33.7 $TERM 027 - 33.700 (xterm-256color ) jsg@jsg-ubuntu:~$ printf "%d %d\n" 070 0x1f 56 31 jsg@jsg-ubuntu:~$ printf "%'d\n" 1234567 1,234,567 jsg@jsg-ubuntu:~$ printf "%5s\n" $(cat /proc/loadavg) 0.00 0.00 0.00 1/452 101619
jsg@jsg-ubuntu:~$ bc scale=5 i=sqrt(2) print i 1.41421
jsg@jsg-ubuntu:~$ echo 'scale=3; i=sqrt(2); print i^2, "\n"' | bc 1.999
jsg@jsg-ubuntu:~$ cat bc_file.bc define fact(n) { tot=1; for (i=n; i>1; i--) { tot *= i; } return tot; } jsg@jsg-ubuntu:~$ echo "fact(10)" | bc bc_file.bc 3628800
jsg@jsg-ubuntu:~$ cat wait.sh #! /bin/bash declare -a pid_child sleep 10 & pid_child[${#pid_child[@]}]=$! sleep 5 & pid_child[${#pid_child[@]}]=$! for ii in ${pid_child[@]} do wait $ii echo "PID[$ii] = $?" done jsg@jsg-ubuntu:~$ bash wait.sh PID[101689] = 0 PID[101690] = 0
옵션 | 설명 |
---|---|
-d | delimeter |
-i | replace string : {} |
-t | verbose 기능 |
jsg@jsg-ubuntu:~$ ls *.txt | xargs -t paste paste a.txt b.txt text a text b hello bye jsg@jsg-ubuntu:~$ ls *.txt | xargs -i cp {} ./backup/{} jsg@jsg-ubuntu:~$ ls ./backup a.txt b.txt