![](/img/trans.png)
[英]How to multiple a number by 2 (double)present in a particular line number of a file, in Linux?
[英]how to restrict length of string present in a line using linux
我有以下形式的数据:
num1 This is a string
num2 This is another string
我想限制在第一个标签之后的所有字符串的长度。这样长度(字符串)<4。 因此,我得到的输出是:
num1 This is a string
num2 This is another
我可以使用python来做到这一点。 但我试图找到一个Linux等价物,以实现相同。
在bash中,您可以使用以下命令限制字符串,在本例中,从索引0到索引17。
$ var="this is a another string"
$ echo ${var:0:17}
this is a another
如果您想截断字边界上的字符串,可以使用带-s选项的fold
:
awk -F"\t" '{
printf "%s\t", $1; system(sprintf("fold -sw 17 <<< \"%s\" | sed q", $2))
}'
缺点是需要为每一行调用fold
和sed
( sed q
与tail -n1
相同)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.