linux / unix 셸 의 awk
준비 작업:
먼저 준비 한 ls. out 의 내용 은 다음 과 같다.
[oracle@localhost testDir]$ cat ls.out 
total 68
-rwxr--r-- 1 oracle oinstall  885 Feb 23 16:23 awk.sh
-rw-r--r-- 1 oracle oinstall  216 Feb 23 11:53 blank_file
-rwxr--r-- 1 oracle oinstall  642 Feb 15 18:43 find.sh
drwxr-xr-x 2 oracle oinstall 4096 Feb 15 17:56 folder
-rw-r--r-- 1 oracle oinstall    0 Feb 23 16:32 ls.out
-rwxr-xr-x 1 oracle oinstall   26 Nov 10 22:30 main.sh
-rwxrwxrwx 1 oracle oinstall   44 Jan  7 22:39 shelltest.sh
-rwxr-xr-x 1 oracle oinstall   99 Feb 23 11:51 test1.sh
-rwxr-xr-x 1 oracle oinstall   99 Feb 23 11:52 test2.sh사실은 ls - l > ls. out 이 특정한 디 렉 터 리 에 저 장 된 파일 목록 입 니 다.
바로 본론 으로 들어가다
#           :
ls -l | awk ' /^[^d]/ {print $9"\t"$5; total+=$5} END {print "the total size of the files is:"total}'
awk.out 121
awk.sh  2250
blank_file      216
find.sh 642
ls.out  511
main.sh 26
shelltest.sh    44
test1.sh        99
test2.sh        99
the total size of the files is:4008
#    279  ,   289   
awk 'gsub(/279/,289) {print $0}' ls.out
#  xr       ,  0     
awk '{print index($1, "xr")"   "$1}' ls.out
0   total
4   -rwxr--r--
0   -rw-r--r--
4   -rwxr--r--
4   drwxr-xr-x
0   -rw-r--r--
4   -rwxr-xr-x
4   -rwxrwxrwx
4   -rwxr-xr-x
4   -rwxr-xr-x
#       awk.sh            
awk '$9=="awk.sh" {print length($9)"   "$9}' ls.out
6   awk.sh
#         test        ,  0     
awk '{print match($9, "test")"   "$9}' ls.out
0  
0   awk.sh
0   blank_file
0   find.sh
0   folder
0   ls.out
0   main.sh
6   shelltest.sh
1   test1.sh
1   test2.sh
# #    ,     123#456#789     myarray ,        
awk 'BEGIN {print split("123#456#789", myarray, "#")}'
3
#          test1.sh      99 100,  
awk '$9=="test1.sh"{print sub(/99/, "100", $0)} {print $0}' ls.out
total 68
-rwxr--r-- 1 oracle oinstall  885 Feb 23 16:23 awk.sh
-rw-r--r-- 1 oracle oinstall  216 Feb 23 11:53 blank_file
-rwxr--r-- 1 oracle oinstall  642 Feb 15 18:43 find.sh
drwxr-xr-x 2 oracle oinstall 4096 Feb 15 17:56 folder
-rw-r--r-- 1 oracle oinstall    0 Feb 23 16:32 ls.out
-rwxr-xr-x 1 oracle oinstall   26 Nov 10 22:30 main.sh
-rwxrwxrwx 1 oracle oinstall   44 Jan  7 22:39 shelltest.sh
1
-rwxr-xr-x 1 oracle oinstall   100 Feb 23 11:51 test1.sh
-rwxr-xr-x 1 oracle oinstall   99 Feb 23 11:52 test2.sh
#    
awk '$9=="awk.sh" {print substr($9, 1, 2)}' ls.out
aw
#      
awk 'BEGIN {STR="lubinsu is the best"} END{print substr(STR, 3)}' ls.out
binsu is the best
#        ,      
STR="lubinsu is the best!"
echo $STR | awk 'END {print substr($STR, 1)}' >> awk.out
lubinsu is the best!
#        :
awk '{printf "%-15s %s
", $1, $9}' ls.out
total          
-rwxr--r--      awk.sh
-rw-r--r--      blank_file
-rwxr--r--      find.sh
drwxr-xr-x      folder
-rw-r--r--      ls.out
-rwxr-xr-x      main.sh
-rwxrwxrwx      shelltest.sh
-rwxr-xr-x      test1.sh
-rwxr-xr-x      test2.sh
#           
awk '{if ($5 < size) print $0}' size=1000 ls.out
total 68
-rwxr--r-- 1 oracle oinstall  885 Feb 23 16:23 awk.sh
-rw-r--r-- 1 oracle oinstall  216 Feb 23 11:53 blank_file
-rwxr--r-- 1 oracle oinstall  642 Feb 15 18:43 find.sh
-rw-r--r-- 1 oracle oinstall    0 Feb 23 16:32 ls.out
-rwxr-xr-x 1 oracle oinstall   26 Nov 10 22:30 main.sh
-rwxrwxrwx 1 oracle oinstall   44 Jan  7 22:39 shelltest.sh
-rwxr-xr-x 1 oracle oinstall   99 Feb 23 11:51 test1.sh
-rwxr-xr-x 1 oracle oinstall   99 Feb 23 11:52 test2.sh
#        :
df -k | awk '($4 ~/^[0-9]/) {printf("%-15s %s
", $6, $4)}'
/               8254824
/boot           265512
/dev/shm        517676
#         
who | awk '{print $1 " is logged on"}'
root is logged on
oracle is logged on
root is logged on
#     
awk 'BEGIN{record="1234#567#890";split(record, myarray, "#")} END{for (i in myarray){print myarray[i]}}' /dev/null
1234
567
890이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
용감한 바로 가기 및 우분투 응용 프로그램안녕하세요 여러분, 이 기사에서는 모든 사이트에서 pwa를 생성하고 실행기 응용 프로그램으로 추가하는 방법을 설명하고 싶습니다. 일부 웹사이트는 PWA로 설치를 허용하지 않지만 유사한 애플리케이션을 원합니다. 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.