当前位置:网站首页>awk注意的几个问题
awk注意的几个问题
2022-06-27 22:57:00 【阳光下的青柠小镇】
1、写一个 bash脚本以统计一个文本文件 ceshi.txt 中每个单词出现的个数
awk '{i=1;while(i<=NF){a[$i]++;i++}}END{for(x in a){print x,a[x]}}' ceshi.txt | sort -nk 2
***注意:***要将一行中的字段分开
以下直接将一行作为处理单位,是错误的
awk '{a[$i]++}END{for(j in a){print a[j],j}}' ceshi.txt | sort -nk 1
2、后面没有跟文本的时候,注意使用BEGIN
3、写一个 bash脚本以统计一个文本文件 nowcoder.txt中字母数小于8的单词
直接用脚本处理较简单
#! /bin/bash
string=$(cat aa.txt)
for i in $string
do
if [ ${
#i} -lt 8 ];then
echo $i
fi
done
其中
${#i}统计字符串i的字符个数
4、写一个 bash脚本以去掉一个文本文件 nowcoder.txt中的空行
awk '!/^$/{print $0}' nowcoder.txt
边栏推荐
- #795 Div.2 E. Number of Groups set *
- Alchemy (2): why use issue management software
- Lodash realizes anti shake and throttling functions and native implementation
- Which securities speculation account opening commission is the cheapest and safest
- Arduino uno realizes simple touch switch through direct detection of capacitance
- 795 div.2 D. Max GEQ sum monotone stack
- How to add live chat in your Shopify store?
- How many securities companies can a person open an account? Is it safe to open an account
- Ceiling scheme 1
- 深入解析kubernetes controller-runtime
猜你喜欢

Modern programming languages: zig

Download, configuration and installation of MySQL

每次启动项目的服务,电脑竟然乖乖的帮我打开了浏览器,100行源码揭秘!

.mp4视频测试地址
Latest MySQL advanced SQL statement Encyclopedia
![[untitled]](/img/e4/7c65c6823559b8501a1777cc4eb7ba.jpg)
[untitled]

Why stainless steel swivel

Introduction to data warehouse

Taro--- day1--- construction project

Matlb| optimal configuration of microgrid in distribution system based on complex network
随机推荐
Taro---day2---编译运行
Learning notes for qstringlist
Official announcement! Apache Doris graduated from the Apache incubator and officially became the top project of Apache!
Code neatness -- format
What is the application scope and function of the conductive slip ring of single crystal furnace
Alchemy (1): identify prototype, demo and MVP in project development
Software engineering job design (1): [personal project] implements a log view page
Differences and functions between intranet IP and public IP
Proe/creo product structure design - continuous research
What is a through-hole conductive slip ring?
Alchemy (4): mental model of programmers
Cloud native O & M article plan
Code neatness -- function
[untitled]
Alchemy (2): why use issue management software
Web mouse click special effects case collection (red heart in live broadcast room)
Alchemy (7): how to solve problems? Only reconstruction
#796 Div.2 C. Manipulating History 思维
攻击队攻击方式复盘总结
Matlb| optimal configuration of microgrid in distribution system based on complex network