請問 grep 或其他 script 做得到嗎? - Linux

Table of Contents

有一筆學生與成績資料如下, 每個字串和數字都是用空格隔開,


xq gg hd ws ki

Jahn amber benson kilo May

35 26 08 21 11

99 76 73 86 32

90 51 89 55 80

想要用搜尋找到 benson 還有 May 的特定學生關鍵字,

然後把 benson 和 Mar 相對應底下第2, 3 行(固定特定行數)的數字取出來,

變成

benson May

08 11

73 32

存成新檔,

請問這樣要有辦法寫嗎?
謝謝.

--

All Comments

Christine avatarChristine2016-05-10
用pandas比較快
Agnes avatarAgnes2016-05-12
一定要用 shell script 的話,先行列轉置,之後再印出
你要的欄位
Carol avatarCarol2016-05-14
cat x | awk 'BEG{count=0}{if(0!=count&&8!=count){
Daph Bay avatarDaph Bay2016-05-17
print $3 "\t" $5} count+=1}'
Thomas avatarThomas2016-05-21
轉置看起來很棒, 能否請在詳細束束一下作法?
Blanche avatarBlanche2016-05-24
位置3 和 5 的數字, 有沒有辦法靠程式自動判斷, 搜尋得到?
Hazel avatarHazel2016-05-28
因為學生名字關鍵字會改變. 謝謝.
Thomas avatarThomas2016-05-31
我想原 po 應該不是要這樣寫死的方式
Linda avatarLinda2016-06-02
我是說樓上上...
帶全家出遊,還沒回到家. 晚點再回.
Dinah avatarDinah2016-06-06
先問一下,第一行的 xq gg 那個是什麼意思?
Bennie avatarBennie2016-06-10
您講的是對的~ 不要寫死.
Kristin avatarKristin2016-06-13
xq gg hd ws ki 表示相對應學生的姓氏