使用 sed,如何打印一行的前 N ​​个字符? [英] Using sed, how do you print the first 'N' characters of a line?

查看:41
本文介绍了使用 sed,如何打印一行的前 N ​​个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用sed 什么是单行打印前n 个字符?我正在做以下事情:

Using sed what is an one liner to print the first n characters? I am doing the following:

grep -G 'defn -test.*' OctaneFullTest.clj  | sed ....

推荐答案

不要使用sed,使用cut:

grep .... | cut -c 1-N

如果你必须使用 sed:

grep ... | sed -e 's/^(.{12}).*/1/'

这篇关于使用 sed,如何打印一行的前 N ​​个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆