簡體   English   中英

為什么在Ruby on Rails中使用“ awk”命令不將任何內容返回變量?

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

目前,我正在執行一項任務,其中我必須閱讀壓縮文件並列出其內容。 我在控制器文件中使用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則它將返回所有內容。 我想做的是根據目錄和文件的級別列出它們。 這就像為壓縮文件創建文件管理系統一樣。

任何幫助,將不勝感激。

您可以發布一些示例輸入/輸出數據,以查看所需內容嗎?

我附近沒有* 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