#!/bin/bash
|
|
#生成 50000 行的文件,每一行可以包含字母、数字。长度不限制。
|
|
for i in $(seq 1 50000)
|
|
do
|
|
echo $RANDOM | md5sum | cut -c 1-9
|
|
done >> test.txt
|
|
|
|
#按照字母顺序排序这个文件,输出所有的 unique 行。
|
|
sort --unique test.txt
|
|
|
|
#按照数字顺序排序这个文件,输出所有的 unique 行。
|
|
sort --unique --numeric-sort test.txt
|
|
|
|
#以覆盖写的方式将上述的结果重定向到一个文件中
|
|
sort --unique test.txt > test1.txt
|
|
sort --unique --numeric-sort test.txt > test1.txt
|
|
|
|
#以追加写的方式将上述的结果重定向到一个文件中
|
|
sort --unique test.txt >> test1.txt
|
|
sort --unique --numeric-sort test.txt >> test1.txt
|
|
|
|
|
|
|
|
#找"computer”
|
|
grep -o "computer" com.txt
|
|
|
|
#统计其中包含多少 computer
|
|
grep -o "computer" com.txt | grep -c "computer"
|