awk

How can I count most occuring sequence of 3 letters within a word with a bash script

爷,独闯天下 提交于 2020-01-21 08:23:06
问题 I have a sample file like XYZAcc ABCAccounting Accounting firm Accounting Aco Accounting Acompany Acoustical consultant Here I need to grep most occurring sequence of 3 letters within a word Output should be acc = 5 aco = 3 Is that possible in Bash? I got absolutely no idea how I can accomplish it with either awk, sed, grep. Any clue how it's possible... PS: no output because I got no idea how to do that, I dont wanna wrote unnecessary awk -F, xyz abc... that not gonna help anywhere... 回答1:

sed和awk有什么区别? [关闭]

≡放荡痞女 提交于 2020-01-20 16:25:23
awk 和 sed 有什么区别? 什么样的应用程序是sed和awk工具的最佳用例? #1楼 1)awk和sed有什么区别? 两者都是改变文本的工具。 但是除了操作文本之外,awk可以做更多的事情。 它本身就是一种编程语言,你在编程中学到的大部分东西,比如数组,循环,if / else流控制等你也可以在sed中“编程”,但是你不想维护写在其中的代码。 2)什么样的应用程序是sed和awk工具的最佳用例? 结论:使用sed进行非常简单的文本解析。 除此之外,awk更好。 事实上,你可以完全抛弃sed并使用awk。 由于它们的功能重叠而awk可以做得更多,所以只需使用awk即可。 您也将减少学习曲线。 #2楼 sed 是一个流编辑器。 它适用于每行的字符流。 它有一个原始的编程语言,包括goto风格的循环和简单的条件(除了模式匹配和地址匹配)。 基本上只有两个“变量”:模式空间和保持空间。 脚本的可读性可能很难。 数学运算充其量只是非常尴尬。 有各种版本的 sed ,对命令行选项和语言功能提供不同级别的支持。 awk 以每行为基础定向分隔字段。 它有更强大的编程结构,包括 if / else , while , do / while 和 for (C风格和数组迭代)。 完全支持变量和单维关联数组加上(IMO)kludgey多维数组。 数学运算类似于C printf 。它具有 printf

ubuntu命令大全

不羁的心 提交于 2020-01-20 10:20:04
查看软件xxx安装内容 dpkg -L xxx 查找软件库中的软件 apt-cache search 正则表达式 查找软件库中的软件 aptitude search 软件包 查找文件属于哪个包 dpkg -S filename 查找文件属于哪个包 apt-file search filename 查询软件xxx依赖哪些包 apt-cache depends xxx 查询软件xxx被哪些包依赖 apt-cache rdepends xxx 增加一个光盘源 sudo apt-cdrom add 系统升级 sudo apt-get update;sudo apt-get dist-upgrade 清除已删除包的残馀配置文件 dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P 编译时缺少h文件的自动处理 sudo auto-apt run ./configure 查看安装软件时下载包的临时存放目录 ls /var/cache/apt/archives 备份当前系统安装的所有包的列表 dpkg –get-selections | grep -v deinstall > ~/somefile 从备份的安装包的列表文件恢复所有包 dpkg –set-selections < ~/somefile;sudo dselect

bc显示小数点前的0

☆樱花仙子☆ 提交于 2020-01-18 23:53:23
bc是强大而常用的计算工具。不过在除法运算时,如果得到的结果值小于1,得到的小数前面的0不存。本篇提供几个常用小数点前缺0的解决方法。 [root@maqing ~]# bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. scale=2; 1/3 .33 打开bc进入交互模式,我们键入scale=2; 1/3 回车,看到结果0.33前的0没有---注意此处保留小数点人2位 scale=2不能少,少了结果为是0 。 解决方法如下: #!/bin/bash #方法1 res1=$(printf "%.2f" `echo "scale=2;1/3"|bc`) res2=$(printf "%.2f" `echo "scale=2;5/3"|bc`) #方法2 #v=$(echo $big $small | awk '{ printf "%0.2f\n" ,$1/$2}') v1=$(echo 1 3 | awk '{ printf "%0.2f\n" ,$1/$2}') v2=$(echo 5

Using awk with variables

感情迁移 提交于 2020-01-18 04:44:14
问题 x=3 A=`echo $A|awk '{print $x}'` echo $A doesnt print 3. How can i use variables with awk* 回答1: Pass variables to awk with the -v flag. x=3 A=`echo $A|awk -v y=$x '{print y}'` echo $A 回答2: You can use the variables of shell by this way: "'$your-shell-variable'" or '$your-shell-variable' . The former considers the variable as string, while the later considers it as number. The following is the code you want: x=3 A=`echo $A|awk '{print "'$x'"}'` echo $A 回答3: Uh, what's the point of echoing $A ?

Transpose column to row without separator in the end [duplicate]

回眸只為那壹抹淺笑 提交于 2020-01-17 14:03:24
问题 This question already has answers here : shell replace cr\lf by comma (8 answers) Turning multi-line string into single comma-separated (17 answers) Closed 3 months ago . I transposed column to row: awk 'BEGIN { ORS = "," } { print }' file File: 45 78 45 The result is: 45,78,45, How to delete the comma in the end of row? I tried: awk 'BEGIN { ORS = "," } { print substr($1, 1, length($1)-1)}' file But it doesn't work for separator. 回答1: For such a simple case the paste command is

Transpose column to row without separator in the end [duplicate]

寵の児 提交于 2020-01-17 14:02:21
问题 This question already has answers here : shell replace cr\lf by comma (8 answers) Turning multi-line string into single comma-separated (17 answers) Closed 3 months ago . I transposed column to row: awk 'BEGIN { ORS = "," } { print }' file File: 45 78 45 The result is: 45,78,45, How to delete the comma in the end of row? I tried: awk 'BEGIN { ORS = "," } { print substr($1, 1, length($1)-1)}' file But it doesn't work for separator. 回答1: For such a simple case the paste command is

How can I count most occuring sequences of 3 letters within a word with a bash script [duplicate]

拜拜、爱过 提交于 2020-01-17 12:45:30
问题 This question already has answers here : How can I count most occuring sequence of 3 letters within a word with a bash script (3 answers) Closed 3 days ago . Indo Cheap has a sample file like XYZAcc ABCAccounting Accounting firm Accounting Aco Accounting Acompany Acoustical consultant He needs to get the most occurring sequences of 3 letters within a word. Output should be acc = 5 aco = 3 He asks if that is possible in bash. He says: "I got absolutely no idea how I can accomplish it with

sed: joining lines depending on the fourth one

拟墨画扇 提交于 2020-01-17 08:43:19
问题 I have a file that, occasionally, has split lines. The split is signaled by the fact that two consecutive lines with Alphabetic characters. 5 00:00:00,000 --> 00:00:00,000 Alphabetic characters Alphabetic characters 6 00:00:00,000 --> 00:00:00,000 Alphabetic characters 7 00:00:00,000 --> 00:00:00,000 Alphabetic characters Alphabetic characters 8 00:00:00,000 --> 00:00:00,000 Alphabetic characters ..... I'd like join the split line back: 5 00:00:00,000 --> 00:00:00,000 Alphabetic characters

Arithmetic calculation in shell scripting-bash

£可爱£侵袭症+ 提交于 2020-01-17 08:41:37
问题 I have an input notepad file as shown below: sample input file: vegetables and rates kg rate total Tomato 4 50 100 potato 2 60 120 Beans 3 80 240 Overalltotal: (100+120++240) = 460 I need to multiply the column 2 and column 3 and check the total if it is right and the overall total as well. If that's not right we need to print in the same file as an error message as shown below enter code here sample output file: vegetables and rates kg rate vegtotal Tomato 4 50 200 potato 2 60 120 Beans 3 80