提取第n个字母(数字) [英] Extract every nth letter (number)
问题描述
我有一个带有以下行的文件:名称,空格和零和一的字符串,我需要提取零和一的字符串的每5n个字符,对结果求和,如果和不为0-将名称保存到另一个文件中.
I have a file with line: name, space and string of zero and one, and I need to extract every 5nth character of the string of zero and one, make a sum of the results and if the sum is not 0 - save the name into the other file.
1rt2 0001000000100000000000001010000100000000010000001000000100010010000000000000
1gh4 0001000000100000000000001010000100000000010000001000000100000010000000000000
3fg5 1000000100010010000000000000100000010000000001000000100000010000000000000000
45gh 1000000100000010000000000000100000010000000001000000000100010000000000000000
问题:如何提取比特串的第5个数字(字母)?解决方案越简单-越好...
The question: how to extract every 5th number (letter) of the bitstring? The more simplistic the solution - the better...
非常感谢!
推荐答案
sed -e '/ \(.........\)*........1/s/^\([^ ]*\) .*$/\1/;t;d'
将位置为1的行与9的倍数匹配(对于这些行,总和将不为0),并打印该行的文件名部分.其他所有行均未打印.
Match the lines that have a 1 on a position that is a multiple of 9 (for these lines the sum will not be 0) and print the filename portion of that line. All other lines are not printed.
sed -e '/ \(.....\)*....1/s/^\([^ ]*\) .*$/\1/;t;d'
每5个0或1执行一次该操作.
will do the job for every 5th 0 or 1.
这篇关于提取第n个字母(数字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!