当前位置:网站首页>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
边栏推荐
- 大尺寸导电滑环市场应用强度如何
- Is it safe to open an account for mobile stocks? Where can I open an account for buying stocks?
- .mp4视频测试地址
- Technical debt wall: a way to make technical debt visible and negotiable
- RNA SEQ introduction practice (I): upstream data download, format conversion and quality control cleaning
- 手机股票开户安全吗,买股票在哪开户?
- plot_model报错:没有安装pydot, graphviz
- Software engineering job design (1): [personal project] implements a log view page
- How to add live chat in your Shopify store?
- Efficient supplier management in supply chain
猜你喜欢

Squid proxy server (Web cache layer for cache acceleration)

Every time I started the service of the project, the computer helped me open the browser, revealing the 100 lines of source code!
最新MySQL高级SQL语句大全

为什么要选择不锈钢旋转接头

GFS 分布式文件系统概述与部署

Introduction to memory model of JVM

Taro--- day2--- compile and run

去哪儿网(Qunar) DevOps 实践分享

云厂商为什么都在冲这个KPI?

Deep parsing of kubernetes controller runtime
随机推荐
1696D. Permutation graph thinking
Form forms and form elements (input, select, textarea, etc.)
股票投资交流群安全吗?入群免费开户靠谱嘛?
哪个证券炒股开户佣金是最便宜,最安全的
Alchemy (8): parallel development and release
Alchemy (4): mental model of programmers
网页鼠标点击特效案例收集(直播间红心同理)
现在炒股网上开户安全吗?新手刚上路,求答案
LabVIEW continuous sampling and limited sampling mode
MATLB|基于复杂网络的配电系统微电网优化配置
Official announcement! Apache Doris graduated from the Apache incubator and officially became the top project of Apache!
Hcip/hcie Routing & Switching / datacom Reference Dictionary Series (19) comprehensive summary of PKI knowledge points (public key infrastructure)
Squid代理服务器(缓存加速之Web缓存层)
zotero文献管理工具安装使用
What is the e-commerce conversion rate so abstract?
云厂商为什么都在冲这个KPI?
Understand the basic structure of wechat applet project
Scu| gait switching and target navigation of micro swimming robot through deep reinforcement learning
Overview and construction of redis master-slave replication, sentinel mode and cluster
Taro--- day1--- construction project