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


相关文章
|
3天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1089 0
|
12天前
|
人工智能 运维 安全
|
2天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
382 8
|
10天前
|
人工智能 测试技术 API
智能体(AI Agent)搭建全攻略:从概念到实践的终极指南
在人工智能浪潮中,智能体(AI Agent)正成为变革性技术。它们具备自主决策、环境感知、任务执行等能力,广泛应用于日常任务与商业流程。本文详解智能体概念、架构及七步搭建指南,助你打造专属智能体,迎接智能自动化新时代。
|
3天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
276 0
|
10天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
11天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
778 23
|
3天前
|
缓存 供应链 监控
VVIC seller_search 排行榜搜索接口深度分析及 Python 实现
VVIC搜款网seller_search接口提供服装批发市场的商品及商家排行榜数据,涵盖热销榜、销量排名、类目趋势等,支持多维度筛选与数据分析,助力选品决策、竞品分析与市场预测,为服装供应链提供有力数据支撑。
|
3天前
|
缓存 监控 API
Amazon item_review 商品评论接口深度分析及 Python 实现
亚马逊商品评论接口(item_review)可获取用户评分、评论内容及时间等数据,支持多维度筛选与分页调用,结合Python实现情感分析、关键词提取与可视化,助力竞品分析、产品优化与市场决策。