用awk通过的文件列表循环? [英] Using awk to iterate through list of files?

查看:383
本文介绍了用awk通过的文件列表循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty不熟悉awk的,但是我正在寻找一种方式来通过目录中的所有文件进行迭代,并执行一个简单的awk命令。我的命令是一个简单的替换替换所有卡口与两个空格。

I'm pretty unfamiliar with Awk, but I am looking for a way to iterate through all files in a directory and execute a simple Awk command. My command is a simple substitution that replaces all tabs with two spaces.

的awk'{GSUB(\\ t的,);}打印

awk '{gsub("\t"," ");print}'

这又如何通过目录扩展到循环,并在所有文件执行的命令?在此先感谢您的帮助!

How can this be extended to loop through a directory and execute the command on all files? Thanks in advance for the help!

推荐答案

及格课程的命令行上的文件的 AWK 的:`

Pass the files to awk on the command line of course: `

$ awk 'program' *

但大概是更容易使用

But probably it is easier to use

$ perl -pe 's/\t/  /g' *

或者,如果你宁愿有一个就地编辑,简单地说:

Or, if you would rather have an inplace edit, simply:

$ perl -i.orig -pe 's/\t/  /g' *

这篇关于用awk通过的文件列表循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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