Re: [問題] 用bash補文字檔中空位

看板Linux作者 (流水)時間10年前 (2015/03/11 23:51), 10年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《zyxwvoklove (天行者)》之銘言: > 1234 1.00 0.44 521 > 2348 123 > 0897 0.92 0.12 886 > 2111 0.23 0.38 589 > --- > 1234 1.00 0.44 521 > 2348 0 0 123 > 0897 0.92 0.12 886 > 2111 0.23 0.38 589 > 請問這要用awk的什麼寫出 > 還是其他command?? 我覺得是可以用awk做出來沒錯,但你說不定拿ruby, python寫比較方便..XD 不過我在試的時候遇到一個問題: > 應該是align好的 > 因為我用awk '{print $2,$3}' filename > 就print出 > 1.00 0.44 > > 0.92 0.12 > 0.23 0.38 我照你給得測資是不會有這個結果得,但如果其實是長這樣: 1234\t1.00\t0.44\t521 2348\t \t \t123 0897\t0.92\t0.12\t886 2111\t0.23\t0.38\t589 這樣我就可以用這樣得command拿到: cat test.in|awk 'FS="\t" {print $2,$3}' 1.00 0.44 0.92 0.12 0.23 0.38 所以你需要得command應該只要: cat test.in|awk 'FS="\t" {print $1, ($2!=" ")?$2:0, ($3!=" ")?$3:0, $4}' 還是要回到你的檔案才會知道該怎麼做... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.89.36 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1426089105.A.A75.html ※ 編輯: soem (220.134.89.36), 03/11/2015 23:52:06
文章代碼(AID): #1L06IHfr (Linux)
文章代碼(AID): #1L06IHfr (Linux)