简体   繁体   English

为什么在Ruby on Rails中使用“ awk”命令不将任何内容返回变量?

[英]Why 'awk' command is not returning anything to variable when used in Ruby on rails?

Currently I am working on a task in which i have to read zipped file and list its contents. 目前,我正在执行一项任务,其中我必须阅读压缩文件并列出其内容。 I am using bash script code in my controller file files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\\n"}' ORS='' |grep "/"|uniq 我在控制器文件中使用bash脚本代码files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\\n"}' ORS='' |grep "/"|uniq files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\\n"}' ORS='' |grep "/"|uniq files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\\n"}' ORS='' |grep "/"|uniq . files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\\n"}' ORS='' |grep "/"|uniq I am trying to get content using this command but I am unable to get the response in variable. 我正在尝试使用此命令获取内容,但无法获得变量的响应。 If i am using files = tar tf 3578336.tar.xz then It returns all the contents. 如果我正在使用files = tar tf 3578336.tar.xz则它将返回所有内容。 What I am trying to do is to list the directories and files according to their levels. 我想做的是根据目录和文件的级别列出它们。 It is like creating a file management system for a zipped file. 这就像为压缩文件创建文件管理系统一样。

Any help would be appreciated. 任何帮助,将不胜感激。

Could you post some sample input/output data, to see what is what you want? 您可以发布一些示例输入/输出数据,以查看所需内容吗?

I don't have a *nix near but you can check if tar is writing the output to stderr or stdout, something like this: 我附近没有* nix,但是您可以检查tar是否将输出写入stderr或stdout,如下所示:

tar tf 3578336.tar.xz 2>/dev/null   #If you can see the filenames, then it writes to stdout

tar tf 3578336.tar.xz >/dev/null   #If you can see the filenames, then it writes to stderr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM