Linux shell programming guide eleventh chapter - combination and division 2

C u t is used from the standard input or text file shear column or domain. Paste the text can be cut to a text file.
The next section describes the paste.
C u t is :
cut [options] file1 file2
The following describes the options available:
-c list specifies the number of characters of shear.
-f field specifies the number of shear field.
-d the specified and empty; and t a B bond different field separator.
C is used to specify the range of cutting, as shown below:
- c 1, 5-7 shear first characters, and then fifth to seventh characters.
50 former -c1-50 shear character.
-f The same with C.
-f 1, 5 shear first field, fifth field.
- f 1, 10-12 shear first field, tenth field and twelfth field.

Refer to section in the file 'p e r s',' p e r now cut from s' file text. The use of colon do the field separator.

[root@localhost huangcd]# cat pers
P.Jones:Office Runner:ID897
S.Round:UNIX admin:ID666
L.Clip:Personl Chief:ID982

The use of colon "file:" as the field separator, it can be used - D option specifies the colon, such as - d:. If you are interested in observing the third domain,
You can use - F 3. To take a I D domain. Use the following command:

[root@localhost huangcd]# cut -d : -f 3 pers

The separated shear field with commas c u t command, such as shear domains 1 and 3, the I name and D number, you can use:

[root@localhost huangcd]# cut -d : -f 1,3 pers

Use the - C option specifies the number of accurate shear. This method needs to know the start and end character. Usually I don't have the party
Method, except in the domain of fixed length or file name.
When the information file transfer to the machine, the file name can identify source file. To obtain this information extraction
Three characters from the file name. Then decided to have what directory. The example below shows a list of files and corresponding
The c u t command:

[root@localhost huangcd]# cat xxx
[root@localhost huangcd]# cat xxx|cut -c 4-6

[root@localhost huangcd]# who -u
root :0 2013-12-02 22:53 ? 4564
root pts/1 2013-12-02 22:56 . 4859 (:0.0)
[root@localhost huangcd]# who -u|cut -c 1-8

C u t is used to from a text file or standard output data extraction column or domain, and then p a s t e to paste the data
Together to form the relevant documents. Paste the two different sources of data, first of all need to classify them, and to ensure that the two file line number.
The same.
P a s t e will be to different file information on a line. By default, the p a s t e connection, with an empty or t a B key to separate
Different text line, unless you specify the - D option, it will become the field separator.
p a s t eFormula,
paste -d -s -file1 file2
The meaning of the following options:
-d specifies the different from the empty or t a B key field separator. Such as @ separated domains, use the - D @.
-s will each file with rows rather than by line paste.
Use standard input. For example, LS -l |paste, which means only display the output in a column.
Has the following two documents from the front of the shear:

P a s t e command to paste into two columns:

[root@localhost huangcd]# cat pas1
[root@localhost huangcd]# cat pas2
[root@localhost huangcd]# paste pas1 pas2
ID897 P.Jones
ID666 S.Round
ID892 L.Clip

To create different from the empty or t a B key field separator, use the - D option. The following examples use a colon to do field separator.

[root@localhost huangcd]# paste -d : pas2 pas1

To merge two lines, but not to paste, you can use the - s option. In the example below, the first line of paste as name, the
The two line is the I D.

[root@localhost huangcd]# paste -s pas2 pas1
P.Jones S.Round L.Clip
ID897 ID666 ID892

P a s t e command has a very useful options (-). Means for each (-), a data read from standard input.
Use the space as the field separator, with a 4 column display directory list. Methods are as follows:

[root@localhost huangcd]# ls files.out nltk-2.0.4 quote.txt
append.sed filetest nltk-2.0.4.tar.gz sedex.txt
c find.dt nohup.out sed.out
change.sed grade.txt pas1 sort.out
data.f grep.err pas2 today
delete_me_and_die huangcdcron pers
Desktop ipython-0.8.2 python vmware-tools-distrib
dht mix.sed PyYAML-3.10 who.out
file1 myfile1.txt PyYAML-3.10.tar.gz wow
filedt myfile.txt qrt.tmp xxx
[root@localhost huangcd]# ls | paste -d " " - - - - append.sed c change.sed
data.f delete_me_and_die Desktop dht
file1 filedt files.out filetest
find.dt grade.txt grep.err huangcdcron
ipython-0.8.2 mix.sed myfile1.txt myfile.txt
nltk-2.0.4 nltk-2.0.4.tar.gz nohup.out pas1
pas2 pers python PyYAML-3.10
PyYAML-3.10.tar.gz qrt.tmp quote.txt sedex.txt
sed.out sort.out today
vmware-tools-distrib who.out wow xxx

[root@localhost huangcd]# ls | paste -d : - - - -

S p l i t is used to split large files into small files. Sometimes more and more documents, send these documents, the segmentation can be
Can more easily. The use of V I or other tools such as s o r t, if the file is too large for the buffer, there are some problems.
It is sometimes no choice, documents must be split into small pieces.
S p l i t command general type:
split -output_file-size input-filename output-filename
Here o u t p u t f I l e s I Z E refers to the text file is divided the line number. S p l i t to view the file, O U T P U T f I l e s I Z E option
The specified file for each up to 1000 line segmentation. If a file has 2800 rows, then divide into 3 files, respectively.
1 0 0 0, 1 0 0 0, The 800 line. Each file type X [a a] x [Z Z], X for the file name initials, [a a], [Z Z] as the file name.
Part of sequential character combination, the example below illustrates this point.

[root@localhost huangcd]# cat split1
this is line1
this is line2
this is line3
this is line4
this is line5
this is line6
[root@localhost huangcd]# split -2 split1
[root@localhost huangcd]# ls -lt |head
A total of 1508
-rw-r--r-- 1 root root 28 12-02 23:18 xaa
-rw-r--r-- 1 root root 84 12-02 23:17 split1

The file has 6 lines, s p l i t according to two lines of each file segmentation, and name the file in alphabetical order. To further make sure.
To be successful, to observe a new file content:

[root@localhost huangcd]# cat xac
this is line5
this is line6


Posted by Lorry at December 13, 2013 - 7:51 PM