awk

Split a string by awk and print everything but the last two splits [closed]

删除回忆录丶 提交于 2020-02-05 02:11:11
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 18 days ago . I have a string /home/lamma/local-blast/termitomycesBGI/short_reads/F19FTSEUHT1394.IC0035-2A_1.fq.gz and I am using awk to split the string: echo /home/lamma/local-blast/termitomycesBGI/short_reads/F19FTSEUHT1394.IC0035-2A.fasta.gz | awk -F'.[^.]*$' '{ print $1 }' Which returns:

【shell】awk可编程过滤器

随声附和 提交于 2020-02-05 01:32:09
目录 简介 1.标准结构 1.1 模式 1.2 动作 2.常用内置变量 3.支持运算符 4.例题 4.1.按行逆序打印 4.2.转置文件 4.3.输出所有子目录信息 4.4.输出第1行以后的行 4.5.列出当前目录下文件名及文件大小 简介 awk 名称由 Alfred A ho (龙书作者;哥伦比亚大学教授)、 Peter J. W einberger(原贝尔实验室科学家;现就职于Google)、Brian K ernighan(顶级技术作家;普林斯顿大学教授)3位组合而来。 awk是一个解释型的、标准的Unix过滤器程序(programmable filter)语言,擅长结构化文本数据处理及报表生成,且执行速度快。 awk可以 读标准输入并写标准输出 ,因此符合经典 过滤器模式 的程序定义,它的 文本过滤功能 需要通过用户自己编程去实现,因此更加强大、丰富、灵活。 1.标准结构 awk程序除了直接命令行使用,还可以协作awk程序文件,以 -f 引用 结构 pattern{action} 缺省 pattern 或者action 模式 过滤每一行的pattern 默认模式:*匹配左右 动作 对每一行的做的操作,如print打印到标准输出 默认动作:打印行 1.1 模式 awk action file.txt awk '{print $0}' file.txt #打印每一行 awk

how can I count number of lines after a string match until next especific match occurs

蓝咒 提交于 2020-02-04 22:57:41
问题 I have a file with the following structure (see below), I need help to find the way to match every ">Cluster" string, and for every case count the number of lines until the next ">cluster" and so on until the end of the file. >Cluster 0 0 10565nt, >CL9602.Contig1_All... * 1 1331nt, >CL9602.Contig2_All... at -/98.05% >Cluster 1 0 3798nt, >CL3196.Contig1_All... at +/97.63% 1 9084nt, >CL3196.Contig3_All... * >Cluster 2 0 8710nt, >Unigene21841_All... * >Cluster 3 0 8457nt, >Unigene10299_All... *

linux_awk小例子

醉酒当歌 提交于 2020-02-04 06:16:41
集群为什么那么慢,等的人无语啊。。。。。。 1:awk '/555555*/' test 打印所有包含模式/555555*/的行 2:awk '{print $1}' test 打印文件的第一个字段,字段从行的左端开始,以空白符分隔 3:awk '{print $1,$3}' test 打印文件的第一,第三个字段 4:awk '/555555/{print $1,$3}' test 打印包含模式/555555/的第一,第三个字段 awk原理: 1):awk使用一行作为输入,并将这一行赋给内部变量$0,默认时每一行也可以称为一个记录,以换行符结束。 2):然后,行被空格分解成字段,每一个字段存储在已编号的变量中,从$1开始,可以多达100个字段。 3):awk如何知道空格是用来分隔字段的呢?因为有另一个内部变量FS用来确定字段的分隔符。初始时,FS被赋为空格——包含制表符和空格符。如果需要使用其他的字符分隔符,如冒号或破折号,则需要将FS变量的值设为新的字段分隔符。 4):awk打印字段时,将以下面的方式使用print函数:{print $1,$3};逗号比较特殊,它映射为另一个内部变量,称为输出字段分隔符OFS,OFS默认为空格。逗号被OFS变量中存储的字符替换。 5):awk输出之后,将从文件中获取另一行,并将其存储到$0中,覆盖原来的内容,然后将新的字符串分隔成字段并进行处理

How to restrict a find and replace to only one column within a CSV?

假如想象 提交于 2020-02-03 10:33:05
问题 I have a 4-column CSV file, e.g.: 0001 @ fish @ animal @ eats worms I use sed to do a find and replace on the file, but I need to limit this find and replace to only the text found inside column 3. How can I have a find and replace only occur on this one column? 回答1: Are you sure you want to be using sed ? What about csvfix? Is your CSV nice and simple with no quotes or embedded commas or other nasties that make regexes...a less than satisfactory way of dealing with a general CSV file? I'm

Separating joined columns with awk

北慕城南 提交于 2020-02-02 11:37:55
问题 I have a data file which looks like the following: 0.00000-130250.92921 28880.20200-159131.13121 301.58706 0.05000-130250.73120 28156.69202-158407.42322 294.03167 0.10000-130250.79137 28237.16138-158487.95275 294.87198 0.15000-130250.81209 28168.63042-158419.44250 294.15634 0.20000-130250.82418 28149.57611-158400.40029 293.95736 0.25000-130250.88438 28069.57135-158320.45573 293.12189 0.30000-130251.06059 28071.30576-158322.36635 293.14000 0.35000-130250.96639 28084.46351-158335.42990 293

Separating joined columns with awk

Deadly 提交于 2020-02-02 11:37:11
问题 I have a data file which looks like the following: 0.00000-130250.92921 28880.20200-159131.13121 301.58706 0.05000-130250.73120 28156.69202-158407.42322 294.03167 0.10000-130250.79137 28237.16138-158487.95275 294.87198 0.15000-130250.81209 28168.63042-158419.44250 294.15634 0.20000-130250.82418 28149.57611-158400.40029 293.95736 0.25000-130250.88438 28069.57135-158320.45573 293.12189 0.30000-130251.06059 28071.30576-158322.36635 293.14000 0.35000-130250.96639 28084.46351-158335.42990 293

AWK: shortened if-then-else with regex

試著忘記壹切 提交于 2020-02-01 11:29:50
问题 The following AWK format: /REGEX/ {Action} Will execute Action if the current line matches REGEX . Is there a way to add an else clause, which will be executed if the current line does not matches the regex, without using if-then-else explicitly, something like: /REGEX/ {Action-if-matches} {Action-if-does-not-match} 回答1: Not so short: /REGEX/ {Action-if-matches} ! /REGEX/ {Action-if-does-not-match} But (g)awk supports the ternary operator too: { /REGEX/ ? matching=1 : matching = 0 ; if (

AWK: shortened if-then-else with regex

 ̄綄美尐妖づ 提交于 2020-02-01 11:27:25
问题 The following AWK format: /REGEX/ {Action} Will execute Action if the current line matches REGEX . Is there a way to add an else clause, which will be executed if the current line does not matches the regex, without using if-then-else explicitly, something like: /REGEX/ {Action-if-matches} {Action-if-does-not-match} 回答1: Not so short: /REGEX/ {Action-if-matches} ! /REGEX/ {Action-if-does-not-match} But (g)awk supports the ternary operator too: { /REGEX/ ? matching=1 : matching = 0 ; if (

linux awk命令详解

最后都变了- 提交于 2020-02-01 08:33:15
awk是行处理器 : 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 awk处理过程: 依次对每一行进行处理,然后输出 awk命令形式: awk [-F|-f|-v] ‘BEGIN{} //{command1; command2} END{}’ file [-F|-f|-v] 大参数,-F指定分隔符,-f调用脚本,-v定义变量 var=value ' ' 引用代码块 BEGIN 初始化代码块,在对每一行进行处理之前,初始化代码,主要是引用全局变量,设置FS分隔符 // 匹配代码块,可以是字符串或正则表达式 {} 命令代码块,包含一条或多条命令 ; 多条命令使用分号分隔 END 结尾代码块,在对每一行进行处理之后再执行的代码块,主要是进行最终计算或输出结尾摘要信息 特殊要点: $0 表示整个当前行 $1 每行第一个字段 NF 字段数量变量 NR 每行的记录号,多文件记录递增 FNR 与NR类似,不过多文件记录不递增,每个文件都从1开始 \t 制表符 \n 换行符 FS BEGIN时定义分隔符 RS 输入的记录分隔符, 默认为换行符(即文本是按一行一行输入) ~ 匹配,与==相比不是精确比较 !~ 不匹配,不精确比较 == 等于,必须全部相等,精确比较 != 不等于,精确比较 &&  逻辑与 || 逻辑或 + 匹配时表示1个或1个以上