wc命令

简介:

wc命令:

输出文件中的行数,单词数,以及字节数

每行输出一个行的数量,单词的数量以及字节的数量。如果指定的文件数量大于1的话,会输出一个总计的行数。

-c:输出字节计数

-m:输出字符数量

-l:输出行数量

-L:输出最长的行的长度

-w:输出单词的数量

--help:显示帮助信息

--version:显示版本信息

实验:

[lichao@sg01 1]$ cat whilecount.cc

/*

 * This file contains code from "C++ Primer, Fourth Edition", by Stanley B.

 * Lippman, Jose Lajoie, and Barbara E. Moo, and is covered under the

 * copyright and warranty notices given in that book:

 *

 * "Copyright (c) 2005 by Objectwrite, Inc., Jose Lajoie, and Barbara E. Moo."

 *

 *

 * "The authors and publisher have taken care in the preparation of this book,

 * but make no expressed or implied warranty of any kind and assume no

 * responsibility for errors or omissions. No liability is assumed for

 * incidental or consequential damages in connection with or arising out of the

 * use of the information or programs contained herein."

 *

 * Permission is granted for this code to be used for educational purposes in

 * association with the book, given proper citation if and when posted or

 * reproduced.Any commercial use of this code requires the explicit written

 * permission of the publisher, Addison-Wesley Professional, a division of

 * Pearson Education, Inc. Send your request for permission, stating clearly

 * what code you would like to use, and in what specific way, to the following

 * address:

 *

 *      Pearson Education, Inc.

 *      Rights and Contracts Department

 *      75 Arlington Street, Suite 300

 *      Boston, MA 02216

 *      Fax: (617) 848-7047

*/

 

#include <iostream>

 

int main()

{

    int sum = 0, val = 1;

    // keep executing the while until val is greater than 10

    while (val <= 10) {

        sum += val;  // assigns sum + val to sum

        ++val;       // add 1 to val

    }

    std::cout << "Sum of 1 to 10 inclusive is "

              << sum << std::endl;

 

    return 0;

}

[lichao@sg01 1]$ cat add_item.cc

/*

 * This file contains code from "C++ Primer, Fourth Edition", by Stanley B.

 * Lippman, Jose Lajoie, and Barbara E. Moo, and is covered under the

 * copyright and warranty notices given in that book:

 *

 * "Copyright (c) 2005 by Objectwrite, Inc., Jose Lajoie, and Barbara E. Moo."

 *

 *

 * "The authors and publisher have taken care in the preparation of this book,

 * but make no expressed or implied warranty of any kind and assume no

 * responsibility for errors or omissions. No liability is assumed for

 * incidental or consequential damages in connection with or arising out of the

 * use of the information or programs contained herein."

 *

 * Permission is granted for this code to be used for educational purposes in

 * association with the book, given proper citation if and when posted or

 * reproduced.Any commercial use of this code requires the explicit written

 * permission of the publisher, Addison-Wesley Professional, a division of

 * Pearson Education, Inc. Send your request for permission, stating clearly

 * what code you would like to use, and in what specific way, to the following

 * address:

 *

 *      Pearson Education, Inc.

 *      Rights and Contracts Department

 *      75 Arlington Street, Suite 300

 *      Boston, MA 02216

 *      Fax: (617) 848-7047

*/

 

#include <iostream>

#include "Sales_item.h"

 

int main()

{

    Sales_item item1, item2;

 

    std::cin >> item1 >> item2;   //read a pair of transactions

    std::cout << item1 + item2 << std::endl; //print their sum

 

    return 0;

}

说明:以上两个cat输出两个文件的内容。

[lichao@sg01 1]$ wc whilecount.cc add.cc

  45  278 1620 whilecount.cc

  46  282 1620 add.cc

  91  560 3240 total

说明:输出每个文件的行数,单词数以及字节数。同时在结尾处输出总的数量。

[lichao@sg01 1]$ wc -l whilecount.cc add.cc

  45 whilecount.cc

  46 add.cc

  91 total

说明:只输出行号

[lichao@sg01 1]$ wc -L whilecount.cc  add.cc

  79 whilecount.cc

  79 add.cc

  79 total

说明:最长的行的长度

[lichao@sg01 1]$ wc -w whilecount.cc add.cc

 278 whilecount.cc

 282 add.cc

 560 total

说明:输出单词的数量

[lichao@sg01 1]$ wc -l *.cc

   46 add.cc

   47 add_item2.cc

   41 add_item.cc

   59 avg_price.cc

   61 count.cc

   45 forcount.cc

   38 for_ex.cc

   44 item_io.cc

   33 main_only.cc

   41 mysum.cc

   61 userforcount.cc

   45 whilecount.cc

  561 total

说明:可以用来统计源代码的行数

[lichao@sg01 1]$ wc -m *.cc

 1620 add.cc

 1735 add_item2.cc

 1514 add_item.cc

 2132 avg_price.cc

 1938 count.cc

 1579 forcount.cc

 1438 for_ex.cc

 1570 item_io.cc

 1308 main_only.cc

 1551 mysum.cc

 1902 userforcount.cc

 1620 whilecount.cc

19907 total

说明:输出每个文件的字符数量。


本文转自hipercomer 51CTO博客,原文链接:http://blog.51cto.com/hipercomer/810333


相关文章
|
2月前
|
Unix Linux Shell
10-17|wc命令是什么
10-17|wc命令是什么
|
4月前
|
Shell Linux Perl
shell 编程中 awk ,wc ,$0,$1 等 命令的使用总结
shell 编程中 awk ,wc ,$0,$1 等 命令的使用总结
116 0
管道符 | shift + 回车上面内容,统计行数 ls -l /user/bin | wc -l,连续过滤cat test.txt | grep itcast | grep itheima
管道符 | shift + 回车上面内容,统计行数 ls -l /user/bin | wc -l,连续过滤cat test.txt | grep itcast | grep itheima
|
6月前
|
数据处理 Perl
AWK 命令20条
AWK 命令示例:显示文件内容、按列打印、计数、使用分隔符、模式匹配、条件语句、数学计算、数组操作、字符串处理、循环、输出格式控制、删除重复行、统计行词字符、分组统计、格式化输出、字段联合、自定义分隔符、字符串截取和调用外部命令。AWK 是强大的文本分析工具,适用于各种数据处理任务。
113 1
|
Linux
Linux命令之wc
Linux命令 wc
73 0
|
6月前
|
自然语言处理 Linux
linux命令之wc
linux命令之wc
51 1
|
Shell
Shell 统计行数(wc -l)
Shell 统计行数(wc -l)
138 0
netstat -antp|wc
netstat -antp|wc
1737 0