::: Zany's Homepage ::: Zany Wiki | 사이트 통합 검색
 
 
 

파일 확장자 추출 (find, awk 조합)

게시판
Unix/Linux
작성자
Zany
작성일
2018-03-23 10:24:50
읽은수
148
평점
   
표시옵션
HTML사용 | 자동BR태그 | 공백문자허용 | 가운데정렬 | 고정폭글꼴 | 자동URL링크 | 마우스선택
find . -type f | awk '{n=split($1,arr1,"/");split(arr1[n],arr2,".");printf("%15s %s\n",arr2[2],$1);}'
● n=split($1,arr1,"/")            - find 명령의 결과를 경로 구분자(/)로 잘라서 arr1 배열에 담고 그 배열의 길이를 n 에 담음.
● split(arr1[n],arr2,".")         - arr1 배열의 n 번째 값이 파일명이므로 파일명, 확장자를 구분하기 위해 "." 으로 잘라서 arr2 배열에 담음.
● printf("%15s %s\n",arr2[2],$1); - arr2 배열의 2번째 값이 확장자이므로 그 값을 출력하고, 원래 값($1)도 출력함
○ printf("%15s %s\n",arr2[length(arr2)],$1) 와 같이 사용 할 수도 있음.
[zany@dione performance-test]$ find . -type f | awk '{n=split($1,arr1,"/");split(arr1[n],arr2,".");printf("%15s %s\n",arr2[2],$1);}'
            key ./bin/res/public.key
            key ./bin/res/private.key
             sh ./bin/run.sh
             md ./README.md
            jar ./gradle/wrapper/gradle-wrapper.jar
     properties ./gradle/wrapper/gradle-wrapper.properties
                ./gradlew
         gradle ./build.gradle
            bin ./.gradle/4.3.1/fileChanges/last-build.bin
           lock ./.gradle/4.3.1/fileHashes/fileHashes.lock
            bin ./.gradle/4.3.1/fileHashes/fileHashes.bin
             sh ./release.sh
            iml ./performance-test.iml
     properties ./gradle.properties
                ./.git/ORIG_HEAD
                ./.git/config
                ./.git/objects/3c/b4845634f5b3af94d56480c532f0f3fce0d36f
                ./.git/objects/3d/a8320375a9b0e5a77103a3d16fabd2b4c0bab6
                ./.git/objects/a4/0cffc16bdc91b2bce7361686ee77d4c6c447aa
                ./.git/objects/df/69ca7561404cf0f0b414cc08d96376689bfc8d
                ./.git/objects/ab/c83250f32d6fd9caf376e39f05f55393c6b419
                ./.git/objects/f4/4304fbc350385dce58e4b1858c2fcb1031c5d6
                ./.git/objects/e4/3c7725f7d9578dfc9de451b954a9940fcfb582
                ./.git/objects/20/1bd7dfe008d1061efc8d5e680f7181e1f1860c
           pack ./.git/objects/pack/pack-1e10c9e3bb3b6c75338252c145cf5e6227a211c0.pack
            idx ./.git/objects/pack/pack-1e10c9e3bb3b6c75338252c145cf5e6227a211c0.idx
                ./.git/objects/11/921ad8db2f3de1dc31504c3455f16f6f7abf6f
                ./.git/objects/17/0a6a3a5723fafc5a527b8c409b7b007f278494
                ./.git/objects/86/62e9d1acdee885cc0a25cd1b496b422d29fd35
                ./.git/objects/31/f9b9400048f774e9cbe8f10b44604819e38764
                ./.git/objects/65/89e445c59cc7fdd2111430f5484365f38d9186
                ./.git/objects/97/a274406279ce9fb3d8e667cbee8a8118e2088c
                ./.git/objects/dd/1d9569ebeb7bf9c9788b679a81bccba615a808
                ./.git/objects/d2/493d1c103dea7a2307b63291519d8ebd3f3300
                ./.git/objects/aa/50e081c135b58792f22b9499877d9e3719b679
                ./.git/objects/a6/ae39af7df9db68b8da96c6cec74462017d8595
                ./.git/objects/cc/129c0a972a0ba635ad36f2eac4548c186c0080
                ./.git/objects/cb/7e64b53ef1ebe3e6f06e7d3d5a99df57bb65d2
                ./.git/objects/2d/8852f482ddc1d0e7bf40cd644174f19466afeb
                ./.git/objects/41/7a42dbc5464694c61719bb6d361891f876b60a
                ./.git/objects/8d/069c1c124b5ec33108cfa882671782516a5d5c
                ./.git/HEAD
                ./.git/info/exclude
                ./.git/logs/HEAD
                ./.git/logs/refs/heads/master
                ./.git/logs/refs/remotes/origin/HEAD
                ./.git/logs/refs/remotes/origin/master
                ./.git/description
         sample ./.git/hooks/commit-msg.sample
         sample ./.git/hooks/pre-rebase.sample
         sample ./.git/hooks/pre-commit.sample
         sample ./.git/hooks/applypatch-msg.sample
         sample ./.git/hooks/pre-receive.sample
         sample ./.git/hooks/prepare-commit-msg.sample
         sample ./.git/hooks/post-update.sample
         sample ./.git/hooks/pre-applypatch.sample
         sample ./.git/hooks/pre-push.sample
         sample ./.git/hooks/update.sample
                ./.git/refs/heads/master
                ./.git/refs/remotes/origin/HEAD
                ./.git/refs/remotes/origin/master
                ./.git/index
                ./.git/packed-refs
                ./.git/COMMIT_EDITMSG
                ./.git/FETCH_HEAD
            bat ./gradlew.bat
         gradle ./settings.gradle
            xml ./.idea/markdown-navigator/profiles_settings.xml
            xml ./.idea/encodings.xml
            xml ./.idea/markdown-navigator.xml
            xml ./.idea/inspectionProfiles/Project_Default.xml
            xml ./.idea/codeStyles/Project.xml
            xml ./.idea/codeStyles/codeStyleConfig.xml
            xml ./.idea/libraries/Gradle__org_slf4j_slf4j_api_1_7_13.xml
            xml ./.idea/libraries/Gradle__ch_qos_logback_logback_core_1_1_3.xml
            xml ./.idea/libraries/Gradle__junit_junit_4_12.xml
            xml ./.idea/libraries/Gradle__com_ktds_apms_commons_apms_commons_0_1_27_SNAPSHOT.xml
            xml ./.idea/libraries/Gradle__ch_qos_logback_logback_classic_1_1_3.xml
            xml ./.idea/libraries/Gradle__commons_io_commons_io_2_5.xml
            xml ./.idea/libraries/Gradle__org_projectlombok_lombok_1_16_20.xml
            xml ./.idea/libraries/Gradle__org_slf4j_log4j_over_slf4j_1_7_13.xml
            xml ./.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
            xml ./.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_7.xml
            xml ./.idea/libraries/Gradle__commons_codec_commons_codec_1_10.xml
            xml ./.idea/libraries/Gradle__com_ktds_point_cipher_cipher_module_0_9_95_SNAPSHOT.xml
            xml ./.idea/gradle.xml
            xml ./.idea/vcs.xml
            xml ./.idea/workspace.xml
            xml ./.idea/modules.xml
            xml ./.idea/dictionaries/zany.xml
            iml ./.idea/modules/performance-test_test.iml
            iml ./.idea/modules/performance-test_main.iml
            xml ./.idea/misc.xml
            xml ./.idea/compiler.xml
           java ./src/test/java/kr/zany/test/etc/TomcatGzipRatioTest.java
           java ./src/test/java/kr/zany/test/exam/timer/MyTimerTask.java
           java ./src/test/java/kr/zany/test/exam/timer/TimerTaskTest.java
           java ./src/test/java/kr/zany/test/exam/counter/MultiThreadCounterTest.java
           java ./src/main/java/kr/zany/test/simple/skeleton/SimpleRunner.java
           java ./src/main/java/kr/zany/test/simple/skeleton/AbstractSimpleRunner.java
           java ./src/main/java/kr/zany/test/performance/skeleton/PerformanceTest.java
           java ./src/main/java/kr/zany/test/performance/skeleton/AbstractPerformanceTest.java
           java ./src/main/java/kr/zany/test/performance/skeleton/AbstractRunnableSupport.java
           java ./src/main/java/kr/zany/test/performance/data/Module.java
           java ./src/main/java/kr/zany/test/performance/data/PrintResult.java
           java ./src/main/java/kr/zany/test/performance/data/ThreadResultVo.java
           java ./src/main/java/kr/zany/test/modules/rsa/RsaCipherRunnable.java
           java ./src/main/java/kr/zany/test/modules/rsa/RsaCipherTest.java
           java ./src/main/java/kr/zany/test/modules/aes256/Aes256CipherRunnable.java
           java ./src/main/java/kr/zany/test/modules/aes256/Aes256CipherTest.java
           java ./src/main/java/kr/zany/test/modules/simple/FillSampleDataTest.java
           java ./src/main/java/kr/zany/test/modules/integer/PrimitiveIntRunnable.java
           java ./src/main/java/kr/zany/test/modules/integer/AtomicCounter.java
           java ./src/main/java/kr/zany/test/modules/integer/Counter.java
           java ./src/main/java/kr/zany/test/modules/integer/AtomicIntRunnable.java
           java ./src/main/java/kr/zany/test/modules/integer/PrimitiveIntTest.java
           java ./src/main/java/kr/zany/test/modules/integer/AtomicIntTest.java
           java ./src/main/java/kr/zany/test/EntryPoint.java


● 현재 디렉토리에 어떤 확장자를 가진 파일들이 있는지...
find . -type f | awk '{n=split($1,arr1,"/");split(arr1[n],arr2,".");printf("%s\n",arr2[2]);}' | sort | uniq -c
[zany@dione performance-test]$ find . -type f | awk '{n=split($1,arr1,"/");split(arr1[n],arr2,".");printf("%s\n",arr2[2]);}' | sort | uniq -c
  40
   1 bat
   2 bin
   2 gradle
   1 idx
   3 iml
   1 jar
  24 java
   2 key
   1 lock
   1 md
   1 pack
   2 properties
  10 sample
   2 sh
  25 xml

게시물이 도움이 되셨으면 +1 을 눌러주세요~
 게시판 글 목록
No Subject Poster Hits Posted
14377 Zany 10 2018-07-11 09:54:33
14376 Zany 26 2018-06-25 15:07:54
14308 Zany 78 2018-05-08 00:40:16
Zany 148 2018-03-23 10:24:50
14273 Zany 146 2018-02-07 13:36:57
14239 Zany 255 2017-12-05 17:07:33
14238 Zany 174 2017-12-05 12:27:02
14234 Zany 249 2017-11-23 13:48:45
14233 Zany 335 2017-11-23 10:17:09
댓글 달기 - 이 글이 도움이 되었거나 흥미로우셨다면, 댓글을 남겨주세요.(^^)(oo)(__)
작성자
                       
 
zany.kr
  Copyright ⓒ 2002-2010 Zany's Programming Lab. All Rights Not Reserved.
temporary This Page loads on 0.063 Secs