简体   繁体   中英

Extract text with awk or sed

I would like to extract and remove some texts from the below

[root@test]# du -k./[a-zA-Z0-9] --max-depth=1 | sort -hr

Before

    7789696 ./b/bklee
    946792  ./a
    796588  ./b/bluecyn
    477860  ./b/bborikun
    473652  ./b/bluechiper
    220780  ./a/ara316
    144244  ./a/aceload
    131088  ./b/belivart
    79108   ./a/athlon85
    78644   ./b/beschur512
    66264   ./b/bogdanov
    52460   ./A

After

    796588  bluecyn
    477860  bborikun
    473652  bluechiper
    220780  ara316
    144244  aceload
    131088  belivart
    79108   athlon85
    78644   beschur512
    66264   bogdanov

what I want is to remove the repetitive pattern, "./a/" and lines that only prints out like "/a" I am trying to figure it out but since I am a beginner at AWK and SED, I need some help.

Thanks!

du -k ./[a-zA-Z0-9] --max-depth=1 | sort -hr | sed -e 's,\./[a-z]/,,; /\.\/[Aa-Zz]/d'

7789696 bklee
796588  bluecyn
477860  bborikun
473652  bluechiper
220780  ara316
144244  aceload
131088  belivart
79108   athlon85
78644   beschur512
66264   bogdanov

Like this, using GNU :

sed -E '/\s\.\/\w$/d; s!\./\w/?!!' file
7789696 bklee
796588 bluecyn
477860 bborikun
473652 bluechiper
220780 ara316
144244 aceload
131088 belivart
79108 athlon85
78644 beschur512
66264 bogdanov

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM