我如何能够有选择性的awk字符串? [英] How can I selectively awk a string?

查看:83
本文介绍了我如何能够有选择性的awk字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不确定宽度的文本行曾在文件中有文字行到重新排序,而我只是想翻转和显示前三个令牌顺序我可以这样做:

If text lines of indeterminate width had in a file had text "Line-to-reorder", and I only wanted to flip and display the order of the first three tokens I can do:

# cat file.txt | awk '/Line-to-reorder/ { print $3 $2 $1 }'

怎样才能让不具有匹配条件通过不变的文本行?

How can I let lines of text that don't have the matching criteria pass through unaltered?

其次,我怎么能显示标记的匹配行余数(该行的剩余)?

Secondly, How can I display the remainder of the tokens (the remainder of the line) on the matched line?

(AWK是因为我的嵌入式系统的实施的busybox有它的首选工具。)

推荐答案

本简单的脚本都回答您的问题:

This simple script answers both your questions:

awk '/Line-to-reorder/ {tmp = $1; $1 = $3; $3 = tmp} {print}' file.txt


  • 您可以分配到字段编辑该行

  • 无需

  • 打印每行(所有领域)

  • 这篇关于我如何能够有选择性的awk字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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