2017-04-13 153 views
0

我有一個輸入文件,其中包含幾個路徑,其中一個引用初始解決方案。相應的線路如下:grep啓動後臺進程

initial_solution_file = ../../INIT/foo 

我想要做的是有這樣我就輸入「初始化」和外殼將返回,將顯示此路徑的別名「最初的解決方案是:../ ../INIT/foo」

我曾嘗試是:

grep initial_solution_file input_file | awk '{print $3}' | echo "the initial solution is:" `xargs echo` 

它提供了所需的輸出,但我additionaly得到的東西,如: [6] 48201 48202

這是什麼以及如何防止它發生?

在此先感謝

+0

嘗試在'grep'前添加'command'。像'command grep initial_solution_file input_file ...' – NullDev

回答

0
echo "the initial solution is: $(awk '/initial_solution_file/{print $3}' input_file)" 
the initial solution is: ../../INIT/foo 

沒有必要管,可以使用$(....)結構做命令替換。另外,grepawk可以單獨由awk完成。

+0

感謝它確實在bash =) 工作但它返回「非法變量名稱。」在tcsh中。任何方式在tcsh中做到這一點? – EdouardIFP

+0

我正確地將它複製到我從tcsh執行的bash腳本中。 這可能是最乾淨的方法,但它的工作原理。 – EdouardIFP