用awk与NSTask [英] Using awk with NSTask

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

问题描述

我将如何使用此awk命令:

How would I use this awk command:

awk 'NR>1{print $1}' string-to-modify

与NSTask?我已经尝试设置的/ usr / bin中/ AWK作为启动路径,'NR大于1 {打印$ 1} 作为参数,则该字符串修改为另一种说法,但我得到的是这样的:

with NSTask? I already tried setting /usr/bin/awk as the launch path, 'NR>1{print $1}' as an argument, then the string to modify as another argument but all I get is this:

/usr/bin/awk: syntax error at source line 1
 context is
     >>> ' <<< 
/usr/bin/awk: bailing out at source line 1

任何帮助将是AP preciated:)

Any help would be appreciated :)

推荐答案

首先,删除单引号: NSTask 不invoque壳可能跨preT他们。这是你的错误的原因。

First, remove single quotes: NSTask doesn't invoque a shell which could interpret them. This is the cause of the error you get.

二, AWK 一个文件名作为最后一个参数,而不是字符串。如果你真的需要NSTask和awk,shell命令将回声串| AWK ... ,这将包括两个NSTask和NSPipe。

Second, awk takes a filename as last argument, not a string. If you really need NSTask and awk, the shell command would be echo string | awk ..., which would involve two NSTask and a NSPipe.

最后,对于字符串manupulation,使用的NSString代替,如提到的dreamlax.

Finally, for string manupulation, use NSString instead, as mentioned by dreamlax.

这篇关于用awk与NSTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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