Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What commands does linux use to process text?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1 、 grep

2. Regular expression

3. Extend regular expressions

4 、 vim

# #

Cat-A

Cat-ns

Cat-b

Tac

Less: pgup; pgdown

? N/N

/

Openssl rand-base64 100 | tr-dc "[: alnum:]" | head-c12

[root@centos6 / app] # openssl rand-base64 100 | tr-dc "[: alnum:]" | head-c124oa9aPP1tr9I

Tail-f is similar: tailf

Tail-F trace file name

Date-d "- 1day"

[root@centos6 / app] # cut-d:-f 1pr 3 / etc/passwd

Df | grep ^ / dev/sd | sed-r "sswap. * [] + ([0-9] {1pm 3})%. * /\ 1 /" df-I | grep ^ / dev/sd | sed-r "sramp. * [] + ([0-9] {1 Magazine 3})%. * /\ 1 /" [root@node4~] # ifconfig eth0 | head-N2 | tail-N1 | tr-s "| cut-d"-f3192.168.137.47 [root@centos6 ~] # ifconfig Eth0 | head-N2 | tail-N1 | cut-d ":"-f2 | cut-d ""-f1192.168.137.6

[root@node4/app] # cut-d:-F1 etc/passwd 3 / etc/passwd | sort-t:-K2-n

Root:0

Bin:1

Daemon:2

Adm:3

Lp:4

Uniq-c

[root@node4/app] # cat / var/log/httpd/access_log | cut-d ""-F1 | sort | uniq-c | sort-nr

7 192.168.137.1

2 192.168.0.118

Diff

Patch

[root@node4/app] # cat F1 whereis [root@node4/app] # cat f2whosi [root@node4/app] # diff-u f1 f2 > diff.log [root@node4/app] # rm-f F1 [root@node4/app] # patch-b f2 diff.log patching file f2Reversed (or previously applied) patch detected! Assume-R? [n] y [root@node4/app] # mv f2 f1 [root@node4/app] # mv f2.orig f2 [root@node4/app] # cat f1 f2whereiswhosi

Linux text processing three Musketeers:

Grep:

Man grep

Grep-nA3 root / etc/passwd

Grep-c

[root@node4/app] # grep-nA3 root / etc/passwd

1:root:x:0:0:root:/root:/bin/bash2-bin:x:1:1:bin:/bin:/sbin/nologin3-daemon:x:2:2:daemon:/sbin:/sbin/nologin4-adm:x:3:4:adm:/var/adm:/sbin/nologin--10:operator:x:11:0:operator:/root:/sbin/nologin11-games:x:12:100:games:/usr/games:/sbin/nologin12-ftp:x : 14:50:FTP User:/var/ftp:/sbin/nologin13-nobody:x:99:99:Nobody:/:/sbin/nologin [root@node4/app] # nmap-v-sP 192.168.137.0 up 24 | grep-B1'up 'Nmap scan report for 192.168.137.1 (192.168.137.1) Host is up (0.00089s latency).-- Nmap scan report for 192.168.137.6 (192.168.137.6) Host is up ( 0.00062s latency). [root@node4/app] # cat nmap.log | grep report | awk'{print $5} '192.168.137.1192.168.137.6

The relation of or expressed by grep-e:

Grep-e root-e bash

Filter words:

[root@node4/app] # echo "x-abc-y" | grep abc

X-abc-y

Man 7 regex

Character matching:. Match any single character [] match any single character within a specified range [^] match any single character [: alnum:] letters and numbers [: alpha:] outside the specified range represent any English uppercase and lowercase character Also known as Amurz Amurz [: lower:] lowercase letters [: upper:] uppercase letters [: blank:] white space characters (spaces and tabs) [: space:] horizontal and vertical white space characters (wider than [: blank:]) [: cntrl:] non-printable control characters (backspace, delete, Alarm bell.) [: digit:] decimal digits [: xdigit:] hexadecimal digits [: graph:] printable non-blank characters [: print:] printable characters [: punct:] punctuation matching times: used after the characters to be specified Used to specify the number of times the previous character will appear * match the previous character any number of times, including 0 greedy mode: match as long as possible. * any character of any length\? Match the character in front of it 0 or 1 times\ + match the character in front of it at least once\ {n\} match the character in front of it at least n times, at most n times\ {n, n\} match the previous character at most n times\ {n,\} match the previous character at least n times position anchor: locate the position where it appears ^ line first anchor The leftmost $line end anchor for the pattern, and the rightmost ^ PATTERN$ for the pattern matching entire line ^ $blank line ^ [[: space:]] * $blank line\

< 或 \b 词首锚定,用于单词模式的左侧\>

Or\ b suffix anchor; used to\ match the entire word on the right side of the word pattern

[root@node4~] # df | grep / dev/sd | grep-o "[0-9]\ +%" | grep-o "[0-9]\ +" | sort-nr | head-N1

twenty-nine

[root@node4~] # echo rootrbbt | grep "\ ([r.. t]\). *\ 1"

Rootrbbt

[root@node4~] # echo rootrbbt | grep "\ (r.. t\). *\ 1"

[root@node4~] # echo rootroot | grep "\ (r.. t\). *\ 1"

Rootroot

[root@node4~] # cat / etc/passwd | grep "^\ (. *\):. * /\ 1 $"

Sync:x:5:0:sync:/sbin:/bin/sync

Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

Halt:x:7:0:halt:/sbin:/sbin/halt

[root@node4~] # cat / etc/passwd | egrep "^ (. *):. * /\ 1 $"

Axy

[root@node4~] # echo axy | egrep "(a | b) xy"

Axy

[root@node4~] # cat / etc/redhat-release | grep-o "[0-9]\ +." | grep-o "[0-9]\ +"

seven

[root@node4~] # cat / etc/centos-release | grep-o "[0-9]\ +" | head-N1

seven

[root@node4~] # echo / etc/rc.d/init.d/ | egrep-o [^ /] * /? $

Init.d/

[root@node4~] # egrep-w "^ (root | sun)" / etc/passwd | cut-d:-F1 Magi 7

Root:/bin/bash

Sun:/bin/bash

Id address:

[0-9]

[1-9] [0-9]

1 [0-9] [0-9]

2 [0-4] [0-9]

25 [0-5]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report