鑑於以下文件的內容:用printf AWK函數輸出第n個參數
alias command with whitespace-separated argument list anotheralias othercommand and its arguments
我怎樣才能打印是這樣的:使用下面的命令
alias = command with whitespace-separated argument list anotheralias = othercommand and its arguments
目前我',但它是錯誤。
cat aliases | awk '{printf "%20s = %s\n", $1, $0}'
這省去了等號。將格式字符串變成'「%20s =」',我想。 –
真實更正。 –
這個工作完美,雖然'貓'是沒有必要的。然而,一個不太聰明的版本可能會更透明:'awk'{name = $ 1; $ 1 = 「」; printf「%20s =%s \ n」,名稱,$ 0}'aliases'。在'='之後沒有空格,因爲現在空的'$ 1'字段後面會出現'$ 0'的前導空格。從邏輯上講,這與上面給出的答案沒有什麼不同。它可能會幫助某人更好地理解爲什麼這個答案有效。 – dubiousjim