Common Linux Commands - Text Processing

Linux text processing tools

  Text processing tools

  • File content: less and cat
  • File interception: head and tail
  • By column extraction: cut
  • Extraction by Keyword: grep

  File Viewer    cat

The Usage: CAT [the OPTION] ... [the FILE] ...
 - end symbol $ E display lines
 - n-number of each line of the display
 - B to a non-empty row number
 folding line empty behavior -s

  tac reverse display file 

  Paged view file contents

  • View more paging file
    • more [options…] file...
    • -d display page and quit tips
    • Turn a blank screen, enter turn one row
    • Output disconnect yourself
  • less page by page view files or stdin Output
    • / Text search text
    • Enter a blank screen row
    • Search Search downward direction N n
    • q to quit
    • less command is a command to use pager man

  Text content before or underwent

  • head [option] ... [file] ... default 10 lines
    • -c # # bytes specified before acquisition
    • -n # Specifies the acquisition front row #
    • - # # specifies the acquisition front line
  • tail [options] ... [file] ... default 10 lines
    • -c # # After obtaining the specified byte
    • -n # # row after a specified acquisition
    • - After acquiring the specified # # row
    • -f file fd trace display newly added content, commonly used to monitor and log
  • tailf similar to tail -f the time when the file does not increase access to the file

  Extract text cut

Cut [Option] ... [the FILE] ...
 - D specified separator, default Tab
 -f # of field # 
# # [#] a plurality of discrete fields, e.g. 1,3,6 
# - # a plurality of consecutive fields 
in combination: 1-3, 7 
- C according to the character cut 
cut -d: -f1 / etc / the passwd 
CAT / etc / the passwd | cut -d: - F7 
cut -c2-5 / etc / the passwd

  Merge Files

paste merge the two files into one row column numbers counterparts 
paste [Option] ... [File] ...
 - D separator delimiter specified, the default is Tab
 - S merged into one line display all rows 
paste F1 F2 
paste - D: F2 f1 
Paste -s f1 F2

  Text analysis tools

  Text statistics wc (word count)

  • Total word count of the total number of rows, the total number of bytes, and total number of characters
  • Statistical data can be in the file or stdin
[CentOS the root @ ~] # WC a.sh 
 . 4 30. 5 a.sh 
 uplink digital file number of bytes
  - L only counts the number of lines
  - W only count the total number of words
  - C only count the total number of bytes
  - m total number of characters counted only
  -L the length of the longest line in the display file

  Text sort sort

The finishing off the text display does not change the original file in stdout

sort [options] files default alphabetical
 - R & lt performed in reverse order
 - R & lt random order
 - n-descending order by number
 - F Ignore case 
-t designated cutting symbol
- TC performed separator -k according to the first columns to sort

  Uniq Remove duplicate lines

After dropping from the input contact duplicate rows

the uniq [Option] ... [File]
 - C shows how many times a line is repeated
 - D show only been repeated rows
 - U never show only duplicate rows 
continuously and exactly the same was repeated for the 
frequently used program 
Sort filename | the uniq - c 
SS-TNP | Cut -d: -f2 | TR -s "" | Cut -d "" -f2 | the Sort -n | uniq -c

  Compare Files

diff filename filename

 

[root@localhost jiangyi]#echo "abc" >b
[root@localhost jiangyi]#echo "abcd" >d
[root@localhost jiangyi]#diff b d
1c1
< abc
---
> abcd
[root@localhost jiangyi]#echo "abcde" >b
[root@localhost jiangyi]#diff b d
1c1
< abcde
---
> abcd
[root@localhost jiangyi]#echo "abcde" >> b
[root@localhost jiangyi]#diff b d
1,2c1
< abcde
< abcde
---
> abcd
[root@localhost jiangyi]#echo "abcd" >> b
[root@localhost jiangyi]#diff b d
1,2d0
< abcde
< abcde

 

Guess you like

Origin www.cnblogs.com/Xiao_Xu/p/11284838.html