awk - create a file based on another file -
i have text file contains following data. example, aa.txt has numbers. need extract continuous numbers(minimum 3 numbers) it.how can awk?
>aa.txt 31 35 36 37 38 39 44 169 170 173 174 175 177 206 >1a.txt 39 40 41 42 146 149 151 my desired output shown below.
>aa.txt 35 36 37 38 39 173 174 175 >1a.txt 39 40 41 42
using awk , example data:
awk 'f+1==$0 {a++} f+1!=$0 {if (a>1) {for (i=f-a;i<=f;i++) print i}a=0} {f=$0}' file 35 36 37 38 39 173 174 175 39 40 41 42 some more readable:
awk ' f+1==$0 { a++} f+1!=$0 { if (a>1) { (i=f-a;i<=f;i++) print }a=0 } {f=$0} ' file how print file name:
awk 'fnr==1 {print ">"filename} f+1==$0 {a++} f+1!=$0 {if (a>1) {for (i=f-a;i<=f;i++) print i}a=0} {f=$0}' * change * match file criteria.
Comments
Post a Comment