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天前
|
弹性计算 运维 搜索推荐
三翼鸟携手阿里云ECS g9i:智慧家庭场景的效能革命与未来生活新范式
三翼鸟是海尔智家旗下全球首个智慧家庭场景品牌,致力于提供覆盖衣、食、住、娱的一站式全场景解决方案。截至2025年,服务近1亿家庭,连接设备超5000万台。面对高并发、低延迟与稳定性挑战,全面升级为阿里云ECS g9i实例,实现连接能力提升40%、故障率下降90%、响应速度提升至120ms以内,成本降低20%,推动智慧家庭体验全面跃迁。
|
3天前
|
数据采集 人工智能 自然语言处理
3分钟采集134篇AI文章!深度解析如何通过云无影AgentBay实现25倍并发 + LlamaIndex智能推荐
结合阿里云无影 AgentBay 云端并发采集与 LlamaIndex 智能分析,3分钟高效抓取134篇 AI Agent 文章,实现 AI 推荐、智能问答与知识沉淀,打造从数据获取到价值提炼的完整闭环。
351 91
|
10天前
|
人工智能 自然语言处理 前端开发
Qoder全栈开发实战指南:开启AI驱动的下一代编程范式
Qoder是阿里巴巴于2025年发布的AI编程平台,首创“智能代理式编程”,支持自然语言驱动的全栈开发。通过仓库级理解、多智能体协同与云端沙箱执行,实现从需求到上线的端到端自动化,大幅提升研发效率,重塑程序员角色,引领AI原生开发新范式。
851 156
|
3天前
|
数据采集 缓存 数据可视化
Android 无侵入式数据采集:从手动埋点到字节码插桩的演进之路
本文深入探讨Android无侵入式埋点技术,通过AOP与字节码插桩(如ASM)实现数据采集自动化,彻底解耦业务代码与埋点逻辑。涵盖页面浏览、点击事件自动追踪及注解驱动的半自动化方案,提升数据质量与研发效率,助力团队迈向高效、稳定的智能化埋点体系。(238字)
257 156
|
4天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
11天前
|
机器人 API 调度
基于 DMS Dify+Notebook+Airflow 实现 Agent 的一站式开发
本文提出“DMS Dify + Notebook + Airflow”三位一体架构,解决 Dify 在代码执行与定时调度上的局限。通过 Notebook 扩展 Python 环境,Airflow实现任务调度,构建可扩展、可运维的企业级智能 Agent 系统,提升大模型应用的工程化能力。
|
人工智能 前端开发 API
前端接入通义千问(Qwen)API:5 分钟实现你的 AI 问答助手
本文介绍如何在5分钟内通过前端接入通义千问(Qwen)API,快速打造一个AI问答助手。涵盖API配置、界面设计、流式响应、历史管理、错误重试等核心功能,并提供安全与性能优化建议,助你轻松集成智能对话能力到前端应用中。
816 154