shell脚本实战训练简单版

本文介绍了如何使用bash Shell脚本处理文本文件,包括计算行数、显示最后5行、输出7的倍数、提取特定行、删除空行以及统计单词频率等实用技巧,适合Linux运维人员学习。
摘要由CSDN通过智能技术生成

一,描述

编写一个shell脚本以输出一个文本文件nowcoder.txt中的行数
示例:
假设 nowcoder.txt 内容如下:

#include <iostream>
using namespace std;
int main()
{
    int a = 10;
    int b = 100;
    cout << "a + b:" << a + b << endl;
    return 0;
}

你的脚本应当输出:
9

 最简单的就是直接用wc -l

[root@localhost ~]# cat nowcoder.txt | wc -l
9

描述

查看日志的时候,经常会从文件的末尾往前查看,请你写一个bash shell脚本以输出一个文本文件nowcoder.txt中的最后5行。
示例:
假设 nowcoder.txt 内容如下:

#include<iostream>
using namespace std;
int main()
{
int a = 10;
int b = 100;
cout << "a + b:" << a + b << endl;
return 0;
}

你的脚本应当输出:

int a = 10;
int b = 100;
cout << "a + b:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值