Shell file processing Tools

Source: Internet
Author: User
Tags diff

vim/etc/resolve.conf View DNS
6.shell script Commands
1.diff
Diff file File compares the differences of two files
-C Displays the surrounding rows
-U generates patches in a uniform output format
-R comparison of files in two directories
Pattch file File.path patch
-B Back up the original file
2.grep
grep Key Character File | Directory finds rows in a file or directory that contain keywords
Grep-i ignoring case
-n Displays the keyword in the row
-C Displays the number of rows for filtered results
-V Reverse Filter
-e "keyword 1| keyword 2" filters multiple keywords
-R directory to find files in the directory that contain keywords
Note: The ^ keyword starts with a keyword
Keyword $ ends with keyword
^root start with Root
root$ End With Root
3.cut
Cut intercept characters
Cut-d delimiter Specifies delimiter
Cut-f 1,7 Displays the specified column
CUT-C display of specified characters
Cut-d ""-F 10 intercepts the space after the tenth column to the next delimiter space between the contents
4.sort sorting
Sort
-N Pure Digit sort
-U Remove Duplicate
|uniq-c Remove duplicates and count repetitions
-T Specify delimiter
-k Specifies the column
SORT-T:-K 2 File-nu
5.uniq
Sort File | Uniq-c remove excess and count repetitions
-D Show Extra rows
-U displays unique rows
6.tr
Tr ' A-Z ' A-z ' file
Sed ' s/original character/replacement character/g ' file
Sed-e ' policy 1 '-e ' policy 2 ' file multiple policies with-E
Sed-i file outputs the transferred files to the specified file
Sed ' 3,5s/original character/replace character/' file
SED xd mask specified line
Sed XP replicates the specified line
Sed-n XP displays only the specified lines
Script
#!/bin/bash
max=$ (Wc-l $ | cut-d ""-F 1)
For NUM in $ (seq $MAX)
Do
username=$ (Sed-n ${num}p$1)
passwd=$ (sed in ${num}p)
Useradd $USERNAME
echo $PASSWD | passwd--STDIN$USERNAMR
Done

7.awk Data processing tool that divides a line into segments for processing, with the smallest number of processing units in a field

awk ' condition type 1{action 1} condition type 2{action 2} ... ' filename
[Email protected] ~]# Last-n 5
Kiosk pts/0:0 Wed Nov 9 19:46 still logged in
Kiosk pts/0:0 Wed Nov 9 18:57-19:46 (00:48)
kiosk:0:0 Wed Nov 9 18:57 still logged in
Reboot system boot 3.10.0-327.el7.x Thu Nov 10 02:56-19:59 ( -6:-57)
kiosk:0:0 Wed Nov 9 17:55-17:55 (00:00)

Wtmp begins Wed Sep 28 00:38:05 2016
[[email protected] ~]# Last-n 5 | awk ' {print $ ' \ t ' $} '
kiosk:0
kiosk:0
kiosk:0
Reboot boot
kiosk:0

$ A represents a whole row of data
Built-in variables
NF total number of fields per row ($)
NR current awk is dealing with the first few rows of data
FS Current separator character, default is space key
[[email protected] ~]# Last-n 5 | awk ' {print $ ' lines: ' NR ' \tcolumes: ' NF} '
Kiosklines:1 columes:10
Kiosklines:2 columes:10
Kiosklines:3 columes:10
Rebootlines:4 columes:11
Kiosklines:5 columes:10
Lines:6 columes:0
Wtmplines:7 columes:7
Condition type
[Email protected] ~]# CAT/ETC/PASSWD | awk ' {fs= ': '} $3<10 {print ' \ t ' $ $} '
Root:x:0:0:root:/root:/bin/bash
Bin 1
Daemon 2
ADM 3
LP 4
Sync 5
Shutdown 6
Halt 7
Mail 8
The first line or the default space bar is the delimiter, want to start from the first line in the delimiter {fs= ":"} before the BEGIN keyword in addition to the end
[Email protected] ~]# CAT/ETC/PASSWD | awk ' begin{fs= ': "} $3<10 {print$1" \ T "$} '
Root 0
Bin 1
Daemon 2
ADM 3
LP 4
Sync 5
Shutdown 6
Halt 7
Mail 8
The awk command calculates
Name 1st 2nd 3th
Zed 12321 34123 41234
Timo 23413 34124 35213
lol 34223 12441 22341
Cat File | awk ' nr==1{printf '%10s%10s%10s%10s%10s\n ", $1,$2,$3,$4," Total "}nr>=2{total=$2+$3+$4 printf"%10d%10d%10d%10d% 10.2f\n,$1,$2,$3,$4,total} '








Shell file processing Tools

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.