Сценарий Bash не работает (sed, grep, sort)

У меня есть скрипт, который я хочу применить к CSV-файлу с именем michael-jordan-nba-career-regular-season-stats-by-game.csv. Я просто пробую очень простые вещи с bash (НЕ AWK). Но когда я запускаю скрипт, ничего не происходит. Странно, потому что только пытаясь запустить первые команды to sed, скрипт уже ничего не делает.

Сценарий

#!/bin/bash

    sed s/CHI/Chicago/g  michael-jordan-nba-career-regular-season-stats-by-game.csv |  #Replacing CHI with Chicago. If it could be only for column 8, better.
    sed s/WAS/Washington/g | #Replacing WAS with Washington. If it could be only for column 8, better.
    grep -v 1985         |   #There is only 1 year column, the first one. Trying to filter out 1985
    sort -n -k 32,32     |   #Trying to sort by column 32, which is PTS
    sed s/1/Home/$9      |   #Trying to replace 1 from column 9 with "Home"
    sed s/0/Away/$9         #Trying to replace 0 from column 9 with "Away"

Вызов:

./b.sh <filename>

Ввод файла:

EndYear,Rk,G,Date,Years,Days,Age,Tm,Home,Opp,Win,Diff,GS,MP,FG,FGA,FG_PCT,3P,3PA,3P_PCT,FT,FTA,FT_PCT,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc
1985,1,1,10/26/1984,21,252,21.6899384,CHI,1,WSB,1,16,1,40,5,16,0.313,0,0,,6,7,0.857,1,5,6,7,2,4,5,2,16,12.5
1985,2,2,10/27/1984,21,253,21.69267625,CHI,0,MIL,0,-2,1,34,8,13,0.615,0,0,,5,5,1,3,2,5,5,2,1,3,4,21,19.4
1985,3,3,10/29/1984,21,255,21.69815195,CHI,1,MIL,1,6,1,34,13,24,0.542,0,0,,11,13,0.846,2,2,4,5,6,2,3,4,37,32.9
1985,4,4,10/30/1984,21,256,21.7008898,CHI,0,KCK,1,5,1,36,8,21,0.381,0,0,,9,9,1,2,2,4,5,3,1,6,5,25,14.7
1985,5,5,11/1/1984,21,258,21.7063655,CHI,0,DEN,0,-16,1,33,7,15,0.467,0,0,,3,4,0.75,3,2,5,5,1,1,2,4,17,13.2
1985,6,6,11/7/1984,21,264,21.72279261,CHI,0,DET,1,4,1,27,9,19,0.474,0,0,,7,9,0.778,1,3,4,3,3,1,5,5,25,14.9
1985,7,7,11/8/1984,21,265,21.72553046,CHI,0,NYK,1,15,1,33,15,22,0.682,0,0,,3,4,0.75,4,4,8,5,3,2,5,2,33,29.3
1985,8,8,11/10/1984,21,267,21.73100616,CHI,0,IND,1,2,1,42,9,22,0.409,0,0,,9,12,0.75,2,7,9,4,2,5,3,4,27,21.2
1985,9,9,11/13/1984,21,270,21.73921971,CHI,1,SAS,1,3,1,43,18,27,0.667,1,1,1,8,11,0.727,2,8,10,4,3,2,4,4,45,37.5
1985,10,10,11/15/1984,21,272,21.74469541,CHI,1,BOS,0,-20,1,33,12,24,0.5,0,1,0,3,3,1,0,2,2,2,2,1,1,4,27,17.1
1985,11,11,11/17/1984,21,274,21.75017112,CHI,1,PHI,0,-9,1,44,4,17,0.235,0,0,,8,8,1,0,5,5,7,5,2,4,5,16,12.5
1985,12,12,11/19/1984,21,276,21.75564682,CHI,1,IND,0,-17,1,39,11,26,0.423,0,3,0,12,16,0.75,2,3,5,2,2,1,3,3,34,20.8
1985,13,13,11/21/1984,21,278,21.76112252,CHI,0,MIL,0,-10,1,42,11,22,0.5,0,0,,13,14,0.929,4,9,13,2,2,2,6,3,35,26.7
1985,14,14,11/23/1984,21,280,21.76659822,CHI,0,SEA,1,19,1,30,9,13,0.692,0,0,,5,6,0.833,0,4,4,3,4,1,4,4,23,19.5
1985,15,15,11/24/1984,21,281,21.76933607,CHI,0,POR,0,-10,1,41,10,24,0.417,0,1,0,10,10,1,3,3,6,8,3,1,4,4,30,23.9
1985,16,16,11/27/1984,21,284,21.77754962,CHI,0,GSW,0,-6,1,24,6,10,0.6,0,0,,1,1,1,0,2,2,3,3,2,4,1,13,11.1
1985,17,17,11/29/1984,21,286,21.78302533,CHI,0,PHO,0,-5,1,30,9,17,0.529,1,1,1,3,4,0.75,1,2,3,2,2,0,2,5,22,14
1985,18,18,11/30/1984,21,287,21.78576318,CHI,0,LAC,1,4,1,37,9,15,0.6,0,0,,2,4,0.5,2,3,5,5,3,0,4,4,20,15.5
1985,19,19,12/2/1984,21,289,21.79123888,CHI,0,LAL,1,1,1,42,7,13,0.538,0,0,,6,8,0.75,2,0,2,3,1,1,4,3,20,12.9
1985,20,20,12/4/1984,21,291,21.79671458,CHI,1,NJN,1,15,1,35,7,13,0.538,0,0,,6,6,1,1,2,3,6,1,0,3,3,20,16
1985,21,21,12/7/1984,21,294,21.80492813,CHI,1,NYK,1,2,1,43,8,16,0.5,0,1,0,5,7,0.714,1,1,2,3,2,0,6,5,21,9.3
1985,22,22,12/8/1984,21,295,21.80766598,CHI,1,DAL,1,2,1,35,10,23,0.435,0,0,,0,0,,4,3,7,2,0,2,2,3,20,11.2
1985,23,23,12/11/1984,21,298,21.81587953,CHI,1,DET,0,-7,1,37,13,28,0.464,0,1,0,1,3,0.333,1,7,8,6,2,0,3,4,27,16.2
1985,24,24,12/12/1984,21,299,21.81861739,CHI,0,DET,0,-7,1,30,6,17,0.353,0,2,0,9,10,0.9,0,1,1,2,2,1,1,5,21,12.5
1985,25,25,12/14/1984,21,301,21.82409309,CHI,0,NJN,0,-2,1,44,12,25,0.48,0,0,,10,10,1,2,6,8,8,1,0,0,4,34,29.5
1985,26,26,12/15/1984,21,302,21.82683094,CHI,1,PHI,0,-12,1,27,7,16,0.438,0,0,,0,0,,1,1,2,2,1,0,1,2,14,7.2
1985,27,27,12/18/1984,21,305,21.83504449,CHI,1,HOU,0,-8,1,45,8,20,0.4,0,1,0,2,4,0.5,1,2,3,8,3,0,1,2,18,14.5
1985,28,28,12/20/1984,21,307,21.84052019,CHI,0,ATL,1,3,1,41,12,22,0.545,0,0,,10,16,0.625,4,4,8,7,5,1,7,5,34,26.6
1985,29,29,12/22/1984,21,309,21.84599589,CHI,1,BOS,1,25,1,35,12,18,0.667,0,0,,8,8,1,1,11,12,8,0,3,3,3,32,31.7
1985,30,30,12/27/1984,21,314,21.85968515,CHI,1,CLE,1,4,1,44,20,33,0.606,0,1,0,5,5,1,2,5,7,11,3,0,3,1,45,40.1
1985,31,31,12/29/1984,21,316,21.86516085,CHI,1,ATL,0,-3,1,39,7,18,0.389,0,0,,7,9,0.778,1,3,4,5,0,0,3,6,21,10.1
1985,32,32,1/2/1985,21,320,21.87611225,CHI,0,ATL,0,-14,1,34,10,14,0.714,0,0,,5,6,0.833,1,6,7,4,3,0,4,2,25,22.3
1985,33,33,1/4/1985,21,322,21.88158795,CHI,1,MIL,1,5,1,38,9,16,0.563,0,1,0,4,5,0.8,0,2,2,6,3,0,0,4,22,20.2
1985,34,34,1/5/1985,21,323,21.8843258,CHI,0,NYK,0,-6,1,42,16,25,0.64,0,0,,10,11,0.909,4,3,7,4,2,1,3,3,42,35.5
1985,35,35,1/9/1985,21,327,21.89527721,CHI,0,BOS,0,-3,1,42,12,24,0.5,0,0,,12,13,0.923,4,2,6,6,2,1,4,4,36,28.3
1985,36,36,1/11/1985,21,329,21.90075291,CHI,1,NYK,1,16,1,30,8,14,0.571,0,0,,7,7,1,2,4,6,5,2,0,5,3,23,18.3
1985,37,37,1/12/1985,21,330,21.90349076,CHI,0,CLE,0,-3,1,36,10,21,0.476,0,1,0,4,6,0.667,4,8,12,3,1,0,3,5,24,15.8
1985,38,38,1/14/1985,21,332,21.90896646,CHI,1,DEN,1,9,1,43,11,16,0.688,0,0,,13,15,0.867,2,12,14,15,3,1,6,3,35,39.4
1985,39,39,1/16/1985,21,334,21.91444216,CHI,0,NJN,0,-6,1,44,8,17,0.471,0,1,0,11,12,0.917,1,6,7,7,2,0,6,3,27,20.1
1985,40,40,1/17/1985,21,335,21.91718001,CHI,1,CLE,1,5,1,40,8,20,0.4,0,0,,9,12,0.75,0,4,4,6,2,2,3,4,25,17.2
1985,41,41,1/19/1985,21,337,21.92265572,CHI,0,IND,0,-3,1,41,15,27,0.556,2,4,0.5,6,8,0.75,2,10,12,7,3,2,2,5,38,34
1985,42,42,1/22/1985,21,340,21.93086927,CHI,1,POR,1,8,1,39,11,20,0.55,0,1,0,7,7,1,1,11,12,5,2,0,4,4,29,23.3
1985,43,43,1/25/1985,21,343,21.93908282,CHI,1,SEA,1,17,1,37,6,15,0.4,0,1,0,10,10,1,2,2,4,8,4,2,1,3,22,24.7
1985,44,44,1/26/1985,21,344,21.94182067,CHI,1,ATL,1,13,1,43,17,24,0.708,0,0,,11,11,1,1,7,8,10,0,4,5,3,45,41.4
1985,45,45,1/29/1985,21,347,21.95003422,CHI,1,KCK,1,6,1,38,11,17,0.647,0,0,,4,6,0.667,0,7,7,7,3,0,1,3,26,25.5
1985,46,46,1/30/1985,21,348,21.95277207,CHI,0,WSB,0,-11,1,41,12,19,0.632,0,0,,14,15,0.933,0,7,7,8,4,0,4,3,38,35.6
1985,47,47,2/1/1985,21,350,21.95824778,CHI,0,PHI,0,-11,1,37,9,16,0.563,0,2,0,13,14,0.929,0,6,6,5,2,0,3,5,31,25.3
1985,48,48,2/5/1985,21,354,21.96919918,CHI,1,BOS,0,-4,1,45,14,25,0.56,0,1,0,13,14,0.929,4,8,12,7,4,1,1,6,41,40.1
1985,49,49,2/7/1985,21,356,21.97467488,CHI,0,CLE,0,-9,1,38,8,17,0.471,0,0,,7,8,0.875,3,1,4,7,4,0,7,6,23,15.8
1985,50,50,2/12/1985,21,361,21.98836413,CHI,1,DET,1,13,1,45,19,31,0.613,0,0,,11,13,0.846,7,8,15,5,4,0,6,5,49,40.9
1985,51,51,2/15/1985,21,364,21.99657769,CHI,1,IND,0,-18,1,37,8,20,0.4,0,1,0,1,2,0.5,1,6,7,6,0,2,4,1,17,9.5
1985,52,52,2/17/1985,22,0,22,CHI,0,MIL,0,-20,1,34,9,15,0.6,0,0,,8,8,1,2,1,3,3,2,1,5,1,26,20.2
1985,53,53,2/19/1985,22,2,22.0054757,CHI,1,LAL,0,-10,1,30,6,13,0.462,0,2,0,4,5,0.8,4,2,6,8,0,0,3,5,16,12.9
1985,54,54,2/22/1985,22,5,22.01368925,CHI,0,BOS,0,-10,1,42,8,18,0.444,0,0,,10,12,0.833,1,3,4,7,3,0,3,3,26,21.1
1985,55,55,2/23/1985,22,6,22.0164271,CHI,1,GSW,1,15,1,32,15,20,0.75,0,0,,8,8,1,1,4,5,5,3,0,0,4,38,36.8
1985,56,56,2/26/1985,22,9,22.02464066,CHI,1,CLE,0,-5,1,48,12,27,0.444,0,1,0,4,4,1,3,6,9,5,0,0,1,4,28,18.7
1985,57,57,2/27/1985,22,10,22.02737851,CHI,0,DET,0,-9,1,35,8,17,0.471,0,1,0,8,9,0.889,1,5,6,2,4,1,4,3,24,18
1985,58,58,3/1/1985,22,12,22.03285421,CHI,1,NYK,1,5,1,38,6,15,0.4,0,0,,9,12,0.75,2,8,10,10,3,0,7,2,21,17.7
1985,59,59,3/3/1985,22,14,22.03832991,CHI,1,NJN,0,-4,1,41,13,21,0.619,0,0,,11,12,0.917,6,8,14,5,3,1,3,2,37,37.1
1985,60,60,3/5/1985,22,16,22.04380561,CHI,1,WSB,1,5,1,44,12,23,0.522,0,0,,13,17,0.765,2,7,9,8,2,1,2,3,37,32.7
1985,61,61,3/6/1985,22,17,22.04654346,CHI,0,BOS,1,3,1,42,13,28,0.464,0,0,,7,7,1,2,5,7,3,5,2,5,2,33,24.2
1985,62,62,3/8/1985,22,19,22.05201916,CHI,1,LAC,1,16,1,28,7,13,0.538,1,2,0.5,11,14,0.786,2,6,8,7,0,1,1,3,26,25.1
1985,63,63,3/9/1985,22,20,22.05475702,CHI,1,UTA,0,-6,1,38,9,21,0.429,1,1,1,9,16,0.563,2,4,6,4,5,0,6,5,28,16.5
1985,64,64,3/11/1985,22,22,22.06023272,CHI,0,WSB,0,-7,1,34,6,14,0.429,0,0,,9,10,0.9,1,3,4,4,0,0,4,2,21,12.8
1985,65,65,3/12/1985,22,23,22.06297057,CHI,1,DET,1,1,1,39,11,24,0.458,0,1,0,10,11,0.909,3,5,8,4,1,0,5,2,32,20.8
1985,66,66,3/14/1985,22,25,22.06844627,CHI,0,NYK,0,-9,1,34,5,18,0.278,0,0,,6,11,0.545,1,2,3,8,1,0,1,3,16,9.1
1985,67,67,3/15/1985,22,26,22.07118412,CHI,1,PHO,1,6,1,42,11,15,0.733,0,0,,5,6,0.833,1,8,9,14,2,2,6,3,27,29.6
1985,68,68,3/17/1985,22,28,22.07665982,CHI,1,MIL,1,2,1,48,11,25,0.44,0,3,0,10,13,0.769,6,5,11,16,1,1,3,5,32,31.3
1985,69,69,3/19/1985,22,30,22.08213552,CHI,0,HOU,0,-6,1,42,11,22,0.5,0,0,,9,10,0.9,2,2,4,7,2,1,7,3,31,21
1985,70,70,3/20/1985,22,31,22.08487337,CHI,0,SAS,0,-8,1,43,14,23,0.609,0,1,0,10,12,0.833,3,4,7,4,3,0,2,5,38,31.8
1985,71,71,3/23/1985,22,34,22.09308693,CHI,0,DAL,1,10,1,43,5,17,0.294,0,0,,10,10,1,3,6,9,10,2,1,1,1,20,22.3
1985,72,72,3/24/1985,22,35,22.09582478,CHI,0,UTA,0,-18,1,35,9,24,0.375,0,0,,8,11,0.727,3,6,9,6,4,2,3,2,26,21.3
1985,73,73,3/26/1985,22,37,22.10130048,CHI,1,IND,1,1,1,40,13,24,0.542,0,1,0,12,13,0.923,4,5,9,5,3,0,3,5,38,31.8
1985,74,74,3/28/1985,22,39,22.10677618,CHI,0,CLE,0,-8,1,41,11,25,0.44,1,3,0.333,12,14,0.857,4,4,8,10,2,0,2,4,35,30.5
1985,75,75,3/30/1985,22,41,22.11225188,CHI,1,PHI,0,-5,1,42,13,19,0.684,1,1,1,11,13,0.846,2,3,5,6,1,0,3,1,38,33.2
1985,76,76,4/2/1985,22,44,22.12046543,CHI,1,NJN,1,14,1,44,12,19,0.632,0,0,,7,8,0.875,5,3,8,9,3,0,7,1,31,28.4
1985,77,77,4/3/1985,22,45,22.12320329,CHI,0,WSB,1,9,1,40,12,19,0.632,0,1,0,1,3,0.333,1,5,6,3,4,0,2,5,25,20
1985,78,78,4/5/1985,22,47,22.12867899,CHI,0,PHI,0,-3,1,38,13,21,0.619,0,1,0,14,15,0.933,0,1,1,5,3,0,2,6,40,32.5
1985,79,79,4/6/1985,22,48,22.13141684,CHI,0,ATL,1,3,1,43,12,18,0.667,0,0,,9,9,1,2,5,7,4,3,2,7,4,33,26.7
1985,80,80,4/8/1985,22,50,22.13689254,CHI,0,IND,0,-4,1,39,6,20,0.3,0,1,0,10,14,0.714,2,6,8,5,3,0,5,2,22,12.7
1985,81,81,4/12/1985,22,54,22.14784394,CHI,1,ATL,0,-11,1,36,11,16,0.688,0,1,0,6,7,0.857,2,1,3,6,5,0,7,3,28,23.5
1985,82,82,4/13/1985,22,55,22.15058179,CHI,0,NJN,0,-12,1,40,9,24,0.375,1,5,0.2,10,11,0.909,2,0,2,9,1,0,4,3,29,18.9
1986,1,1,10/25/1985,22,250,22.6844627,CHI,1,CLE,1,1,1,39,13,26,0.5,0,0,,3,4,0.75,3,3,6,3,3,0,3,5,29,18.7
1986,2,2,10/26/1985,22,251,22.68720055,CHI,1,DET,1,3,1,41,9,24,0.375,0,0,,15,16,0.938,2,5,7,6,2,3,6,5,33,22.6
1986,3,3,10/29/1985,22,254,22.6954141,CHI,0,GSW,1,6,1,18,6,10,0.6,0,0,,0,0,,0,2,2,2,0,0,1,1,12,8
1986,4,4,3/15/1986,23,26,23.07118412,CHI,1,MIL,0,-9,0,13,4,7,0.571,0,0,,4,7,0.571,0,1,1,2,1,0,1,2,12,8.4
1986,5,5,3/17/1986,23,28,23.07665982,CHI,0,ATL,0,-10,0,14,4,16,0.25,0,1,0,9,10,0.9,3,1,4,1,7,1,1,0,17,16.8
1986,6,6,3/19/1986,23,30,23.08213552,CHI,0,PHI,0,-6,0,15,4,14,0.286,0,2,0,4,6,0.667,4,0,4,3,2,2,1,1,12,9.9
1986,7,7,3/21/1986,23,32,23.08761123,CHI,0,BOS,0,-21,0,16,7,16,0.438,0,1,0,6,7,0.857,2,0,2,1,0,1,1,3,20,11.8
1986,8,8,3/22/1986,23,33,23.09034908,CHI,0,CLE,0,-26,0,16,4,13,0.308,0,0,,0,1,0,1,0,1,1,0,0,1,2,8,-0.3
1986,9,9,3/25/1986,23,36,23.09856263,CHI,1,NYK,1,13,0,19,5,12,0.417,0,1,0,9,9,1,1,2,3,3,1,0,2,3,19,13.8
1986,10,10,3/28/1986,23,39,23.10677618,CHI,0,NJN,0,-11,0,22,9,15,0.6,0,0,,4,6,0.667,0,1,1,3,5,0,3,4,22,17.1
1986,11,11,3/29/1986,23,40,23.10951403,CHI,0,NYK,1,10,0,23,10,17,0.588,0,1,0,4,6,0.667,1,0,1,1,1,3,4,2,24,15
1986,12,12,4/1/1986,23,43,23.11772758,CHI,0,MIL,0,-9,0,26,8,16,0.5,0,1,0,12,12,1,1,4,5,2,1,3,1,2,28,24.6
1986,13,13,4/3/1986,23,45,23.12320329,CHI,0,IND,1,1,0,28,12,19,0.632,0,0,,2,4,0.5,1,4,5,3,3,2,3,1,26,21.7
1986,14,14,4/5/1986,23,47,23.12867899,CHI,1,ATL,1,5,0,31,10,21,0.476,2,3,0.667,8,9,0.889,1,2,3,3,1,1,4,1,30,19.6
1986,15,15,4/7/1986,23,49,23.13415469,CHI,1,MIL,1,6,1,31,10,18,0.556,1,3,0.333,5,5,1,1,4,5,7,1,3,2,3,26,24.1
1986,16,16,4/8/1986,23,50,23.13689254,CHI,0,ATL,0,-13,1,33,12,25,0.48,0,2,0,6,6,1,1,5,6,6,2,1,7,2,30,18.6
1986,17,17,4/11/1986,23,53,23.14510609,WAS,1,WSB,1,2,1,37,12,36,0.333,0,1,0,7,10,0.7,1,4,5,2,3,1,2,5,31,12.4
1986,18,18,4/13/1986,23,55,23.15058179,WAS,0,CLE,0,-7,1,29,11,23,0.478,0,2,0,7,7,1,0,3,3,4,4,0,2,4,29,21.4

Ожидаемый результат:

EndYear,Rk,G,Date,Years,Days,Age,Tm,Home,Opp,Win,Diff,GS,MP,FG,FGA,FG_PCT,3P,3PA,3P_PCT,FT,FTA,FT_PCT,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc
1986,1,1,10/25/1985,22,250,22.6844627,Chicago,Home,CLE,1,1,1,39,13,26,0.5,0,0,,3,4,0.75,3,3,6,3,3,0,3,5,29,18.7
1986,2,2,10/26/1985,22,251,22.68720055,Chicago,Home,DET,1,3,1,41,9,24,0.375,0,0,,15,16,0.938,2,5,7,6,2,3,6,5,33,22.6
1986,3,3,10/29/1985,22,254,22.6954141,Chicago,Away,GSW,1,6,1,18,6,10,0.6,0,0,,0,0,,0,2,2,2,0,0,1,1,12,8
1986,4,4,3/15/1986,23,26,23.07118412,Chicago,Home,MIL,0,-9,0,13,4,7,0.571,0,0,,4,7,0.571,0,1,1,2,1,0,1,2,12,8.4
1986,5,5,3/17/1986,23,28,23.07665982,Chicago,Away,ATL,0,-10,0,14,4,16,0.25,0,1,0,9,10,0.9,3,1,4,1,7,1,1,0,17,16.8
1986,6,6,3/19/1986,23,30,23.08213552,Chicago,Away,PHI,0,-6,0,15,4,14,0.286,0,2,0,4,6,0.667,4,0,4,3,2,2,1,1,12,9.9
1986,7,7,3/21/1986,23,32,23.08761123,Chicago,Away,BOS,0,-21,0,16,7,16,0.438,0,1,0,6,7,0.857,2,0,2,1,0,1,1,3,20,11.8
1986,8,8,3/22/1986,23,33,23.09034908,Chicago,Away,CLE,0,-26,0,16,4,13,0.308,0,0,,0,1,0,1,0,1,1,0,0,1,2,8,-0.3
1986,9,9,3/25/1986,23,36,23.09856263,Chicago,Home,NYK,1,13,0,19,5,12,0.417,0,1,0,9,9,1,1,2,3,3,1,0,2,3,19,13.8
1986,10,10,3/28/1986,23,39,23.10677618,Chicago,Away,NJN,0,-11,0,22,9,15,0.6,0,0,,4,6,0.667,0,1,1,3,5,0,3,4,22,17.1
1986,11,11,3/29/1986,23,40,23.10951403,Chicago,Away,NYK,1,10,0,23,10,17,0.588,0,1,0,4,6,0.667,1,0,1,1,1,3,4,2,24,15
1986,12,12,04/01/1986,23,43,23.11772758,Chicago,Away,MIL,0,-9,0,26,8,16,0.5,0,1,0,12,12,1,1,4,5,2,1,3,1,2,28,24.6
1986,13,13,04/03/1986,23,45,23.12320329,Chicago,Away,IND,1,1,0,28,12,19,0.632,0,0,,2,4,0.5,1,4,5,3,3,2,3,1,26,21.7
1986,14,14,04/05/1986,23,47,23.12867899,Chicago,Home,ATL,1,5,0,31,10,21,0.476,2,3,0.667,8,9,0.889,1,2,3,3,1,1,4,1,30,19.6
1986,15,15,04/07/1986,23,49,23.13415469,Chicago,Home,MIL,1,6,1,31,10,18,0.556,1,3,0.333,5,5,1,1,4,5,7,1,3,2,3,26,24.1
1986,16,16,04/08/1986,23,50,23.13689254,Chicago,Away,ATL,0,-13,1,33,12,25,0.48,0,2,0,6,6,1,1,5,6,6,2,1,7,2,30,18.6
1986,17,17,04/11/1986,23,53,23.14510609,Washington,Home,WSB,1,2,1,37,12,36,0.333,0,1,0,7,10,0.7,1,4,5,2,3,1,2,5,31,12.4
1986,18,18,4/13/1986,23,55,23.15058179,Washington,Away,CLE,0,-7,1,29,11,23,0.478,0,2,0,7,7,1,0,3,3,4,4,0,2,4,29,21.4

Большое спасибо.

Как только я заработаю скрипт, в идеале было бы неплохо сохранить результат в другой скрипт с именем b.awk, я думаю, с > b.awk, но я не знаю, куда его поместить.

Я не уверен, почему вы не хотите использовать awk; с ним проще манипулировать полями.

Fravadona 16.05.2022 20:25

Я знаю и буду. Мне просто нужно предоставить разные сценарии, и я делаю bash. Позже мне нужно будет сделать с awk, который, я согласен, больше подходит пользователю. Но в настоящее время, чтобы изучить основы, меня попросили сделать это с помощью bash.

Jose Antonio Piedehierro Arias 16.05.2022 20:27

Хорошо, тогда вы уверены, что можете использовать sed, grep и sort? Как и awk, это стандартные инструменты, но не bash.

Fravadona 16.05.2022 20:32

Хороший вопрос. Мне нужно написать полный сценарий bash и полный сценарий awk. Какая команда будет считаться bash для модификации данных???

Jose Antonio Piedehierro Arias 16.05.2022 20:34

См. мой обновленный ответ для решения на чистом bash. Я никогда не думал, что когда-нибудь напишу алгоритм сортировки на bash, но на самом деле это довольно просто для положительных целых чисел.

Fravadona 16.05.2022 22:38
Формы c голосовым вводом в React с помощью Speechly
Формы c голосовым вводом в React с помощью Speechly
Пытались ли вы когда-нибудь заполнить веб-форму в области электронной коммерции, которая требует много кликов и выбора? Вас попросят заполнить дату,...
Стилизация и валидация html-формы без использования JavaScript (только HTML/CSS)
Стилизация и валидация html-формы без использования JavaScript (только HTML/CSS)
Будучи разработчиком веб-приложений, легко впасть в заблуждение, считая, что приложение без JavaScript не имеет права на жизнь. Нам становится удобно...
Flatpickr: простой модуль календаря для вашего приложения на React
Flatpickr: простой модуль календаря для вашего приложения на React
Если вы ищете пакет для быстрой интеграции календаря с выбором даты в ваше приложения, то библиотека Flatpickr отлично справится с этой задачей....
В чем разница между Promise и Observable?
В чем разница между Promise и Observable?
Разберитесь в этом вопросе, и вы значительно повысите уровень своей компетенции.
Что такое cURL в PHP? Встроенные функции и пример GET запроса
Что такое cURL в PHP? Встроенные функции и пример GET запроса
Клиент для URL-адресов, cURL, позволяет взаимодействовать с множеством различных серверов по множеству различных протоколов с синтаксисом URL.
Четыре эффективных способа центрирования блочных элементов в CSS
Четыре эффективных способа центрирования блочных элементов в CSS
У каждого из нас бывали случаи, когда нам нужно отцентрировать блочный элемент, но мы не знаем, как это сделать. Даже если мы реализуем какой-то...
1
5
73
3
Перейти к ответу Данный вопрос помечен как решенный

Ответы 3

Вы не говорите sed/grep/sort читать свои данные откуда угодно, поэтому все они по умолчанию будут читать данные со стандартного ввода. Измените свой сценарий, чтобы он запускал первую команду во входном файле, который вы передаете, и передаете все последующие команды на его вывод:

sed s/CHI/Chicago/g "$1" | #Replacing CHI with Chicago. If it could be only for column 8, better.
sed s/WAS/Washington/g   | #Replacing WAS with Washington. If it could be only for column 8, better.
grep -v 1985             | #There is only 1 year column, the first one. Trying to filter out 1985
sort -n -k 32,32         | #Trying to sort by column 32, which is PTS
sed s/1/Home/$9          | #Trying to replace 1 from column 9 with "Home"
sed s/0/Away/$9            #Trying to replace 0 from column 9 with "Away"

Пожалуйста, смотрите обновленный мой сценарий. Как это? Считаете ли вы сортировку и последние 2 sed правильными?

Jose Antonio Piedehierro Arias 16.05.2022 20:24

последние 2 sed неверны, так как $9 будет оцениваться bash как пустая строка; вы должны использовать set -euo pipefail в качестве первой строки после #!/bin/bash, чтобы заставить bash сообщать вам об ошибке в таких случаях.

Costi Ciudatu 16.05.2022 20:27

sort также не подходит, потому что вы используете разделитель столбцов по умолчанию (пробелы). Попробуйте это вместо этого: sort -t ',' -k 32 -n

Costi Ciudatu 16.05.2022 20:28

Хорошо, большое спасибо за ваш вклад. Возвращаясь к последним 2 командам sed. Как я могу сказать sed ограничить замену только одним столбцом? Спасибо!!

Jose Antonio Piedehierro Arias 16.05.2022 20:28

Я думаю, что sed знает, как заменить только первое вхождение или все вхождения, но не какое-то конкретное вхождение в вашем вводе. Я думаю, вы захотите попробовать awk для этого.

Costi Ciudatu 16.05.2022 20:33
Ответ принят как подходящий

But currently in order to learn the fundamentals I've been asked to do it with bash

Я бы сказал, что делать это в чистом bash — это гораздо больше, чем просто основы, но вот как вы можете заменить sed, grep и sort в вашем случае использования. remark: The sorting is possible because PTS is an integer (shell arithmetic is for integers only), but I don't use numerical comparisons here, I take advantage of the fact that the integers in the data are all positives, which allows to use them as array indexes (bash arrays can be sparse).

#!/bin/bash

IFS=',' records=() sorted=()
{
    IFS='' read -r header

    while read -r -a values
    do
        [[ ${values[0]} != 1985 ]] || continue

        case ${values[7]} in
            CHI) values[7]=Chicago ;;
            WAS) values[7]=Washington ;;
        esac

        case ${values[8]} in
            0) values[8]=Away ;;
            1) values[8]=Home ;;
        esac

        pts=${values[31]} 
        sorted[pts]+=${sorted[pts]:+$IFS}${#records[@]}
        records+=( "${values[*]}" )

    done
} < file.csv

printf '%s\n' "$header"

for i in ${sorted[*]} # unquoted expansion
do
    printf '%s\n' "${records[i]}"
done
EndYear,Rk,G,Date,Years,Days,Age,Tm,Home,Opp,Win,Diff,GS,MP,FG,FGA,FG_PCT,3P,3PA,3P_PCT,FT,FTA,FT_PCT,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc
1986,8,8,3/22/1986,23,33,23.09034908,Chicago,Away,CLE,0,-26,0,16,4,13,0.308,0,0,,0,1,0,1,0,1,1,0,0,1,2,8,-0.3
1986,3,3,10/29/1985,22,254,22.6954141,Chicago,Away,GSW,1,6,1,18,6,10,0.6,0,0,,0,0,,0,2,2,2,0,0,1,1,12,8
1986,4,4,3/15/1986,23,26,23.07118412,Chicago,Home,MIL,0,-9,0,13,4,7,0.571,0,0,,4,7,0.571,0,1,1,2,1,0,1,2,12,8.4
1986,6,6,3/19/1986,23,30,23.08213552,Chicago,Away,PHI,0,-6,0,15,4,14,0.286,0,2,0,4,6,0.667,4,0,4,3,2,2,1,1,12,9.9
1986,5,5,3/17/1986,23,28,23.07665982,Chicago,Away,ATL,0,-10,0,14,4,16,0.25,0,1,0,9,10,0.9,3,1,4,1,7,1,1,0,17,16.8
1986,9,9,3/25/1986,23,36,23.09856263,Chicago,Home,NYK,1,13,0,19,5,12,0.417,0,1,0,9,9,1,1,2,3,3,1,0,2,3,19,13.8
1986,7,7,3/21/1986,23,32,23.08761123,Chicago,Away,BOS,0,-21,0,16,7,16,0.438,0,1,0,6,7,0.857,2,0,2,1,0,1,1,3,20,11.8
1986,10,10,3/28/1986,23,39,23.10677618,Chicago,Away,NJN,0,-11,0,22,9,15,0.6,0,0,,4,6,0.667,0,1,1,3,5,0,3,4,22,17.1
1986,11,11,3/29/1986,23,40,23.10951403,Chicago,Away,NYK,1,10,0,23,10,17,0.588,0,1,0,4,6,0.667,1,0,1,1,1,3,4,2,24,15
1986,13,13,4/3/1986,23,45,23.12320329,Chicago,Away,IND,1,1,0,28,12,19,0.632,0,0,,2,4,0.5,1,4,5,3,3,2,3,1,26,21.7
1986,15,15,4/7/1986,23,49,23.13415469,Chicago,Home,MIL,1,6,1,31,10,18,0.556,1,3,0.333,5,5,1,1,4,5,7,1,3,2,3,26,24.1
1986,12,12,4/1/1986,23,43,23.11772758,Chicago,Away,MIL,0,-9,0,26,8,16,0.5,0,1,0,12,12,1,1,4,5,2,1,3,1,2,28,24.6
1986,1,1,10/25/1985,22,250,22.6844627,Chicago,Home,CLE,1,1,1,39,13,26,0.5,0,0,,3,4,0.75,3,3,6,3,3,0,3,5,29,18.7
1986,18,18,4/13/1986,23,55,23.15058179,Washington,Away,CLE,0,-7,1,29,11,23,0.478,0,2,0,7,7,1,0,3,3,4,4,0,2,4,29,21.4
1986,14,14,4/5/1986,23,47,23.12867899,Chicago,Home,ATL,1,5,0,31,10,21,0.476,2,3,0.667,8,9,0.889,1,2,3,3,1,1,4,1,30,19.6
1986,16,16,4/8/1986,23,50,23.13689254,Chicago,Away,ATL,0,-13,1,33,12,25,0.48,0,2,0,6,6,1,1,5,6,6,2,1,7,2,30,18.6
1986,17,17,4/11/1986,23,53,23.14510609,Washington,Home,WSB,1,2,1,37,12,36,0.333,0,1,0,7,10,0.7,1,4,5,2,3,1,2,5,31,12.4
1986,2,2,10/26/1985,22,251,22.68720055,Chicago,Home,DET,1,3,1,41,9,24,0.375,0,0,,15,16,0.938,2,5,7,6,2,3,6,5,33,22.6

Обновление (печать заголовка и изменение отсортированного вывода):
#!/bin/bash

IFS=',' records=() sorted=()
{
    IFS='' read -r header

    while read -r -a values
    do
        [[ ${values[0]} == 1986 ]] || continue

        case ${values[7]} in
            CHI) values[7]=Chicago ;;
            WAS) values[7]=Washington ;;
        esac

        case ${values[8]} in
            0) values[8]=Away ;;
            1) values[8]=Home ;;
        esac

        pts=${values[31]}

        sorted[pts]+=${sorted[pts]:+$IFS}${#records[@]}
        records+=( "${values[*]}" )
    done
} < file.csv

sorted=( ${sorted[*]} ) # unquoted expansion

printf '%s\n' "$header"

for ((i = ${#sorted[@]}-1; i >= 0; i--))
do
    printf '%s\n' "${records[sorted[i]]}"
done
EndYear,Rk,G,Date,Years,Days,Age,Tm,Home,Opp,Win,Diff,GS,MP,FG,FGA,FG_PCT,3P,3PA,3P_PCT,FT,FTA,FT_PCT,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc
1986,2,2,10/26/1985,22,251,22.68720055,Chicago,Home,DET,1,3,1,41,9,24,0.375,0,0,,15,16,0.938,2,5,7,6,2,3,6,5,33,22.6
1986,17,17,4/11/1986,23,53,23.14510609,Washington,Home,WSB,1,2,1,37,12,36,0.333,0,1,0,7,10,0.7,1,4,5,2,3,1,2,5,31,12.4
1986,16,16,4/8/1986,23,50,23.13689254,Chicago,Away,ATL,0,-13,1,33,12,25,0.48,0,2,0,6,6,1,1,5,6,6,2,1,7,2,30,18.6
1986,14,14,4/5/1986,23,47,23.12867899,Chicago,Home,ATL,1,5,0,31,10,21,0.476,2,3,0.667,8,9,0.889,1,2,3,3,1,1,4,1,30,19.6
1986,18,18,4/13/1986,23,55,23.15058179,Washington,Away,CLE,0,-7,1,29,11,23,0.478,0,2,0,7,7,1,0,3,3,4,4,0,2,4,29,21.4
1986,1,1,10/25/1985,22,250,22.6844627,Chicago,Home,CLE,1,1,1,39,13,26,0.5,0,0,,3,4,0.75,3,3,6,3,3,0,3,5,29,18.7
1986,12,12,4/1/1986,23,43,23.11772758,Chicago,Away,MIL,0,-9,0,26,8,16,0.5,0,1,0,12,12,1,1,4,5,2,1,3,1,2,28,24.6
1986,15,15,4/7/1986,23,49,23.13415469,Chicago,Home,MIL,1,6,1,31,10,18,0.556,1,3,0.333,5,5,1,1,4,5,7,1,3,2,3,26,24.1
1986,13,13,4/3/1986,23,45,23.12320329,Chicago,Away,IND,1,1,0,28,12,19,0.632,0,0,,2,4,0.5,1,4,5,3,3,2,3,1,26,21.7
1986,11,11,3/29/1986,23,40,23.10951403,Chicago,Away,NYK,1,10,0,23,10,17,0.588,0,1,0,4,6,0.667,1,0,1,1,1,3,4,2,24,15
1986,10,10,3/28/1986,23,39,23.10677618,Chicago,Away,NJN,0,-11,0,22,9,15,0.6,0,0,,4,6,0.667,0,1,1,3,5,0,3,4,22,17.1
1986,7,7,3/21/1986,23,32,23.08761123,Chicago,Away,BOS,0,-21,0,16,7,16,0.438,0,1,0,6,7,0.857,2,0,2,1,0,1,1,3,20,11.8
1986,9,9,3/25/1986,23,36,23.09856263,Chicago,Home,NYK,1,13,0,19,5,12,0.417,0,1,0,9,9,1,1,2,3,3,1,0,2,3,19,13.8
1986,5,5,3/17/1986,23,28,23.07665982,Chicago,Away,ATL,0,-10,0,14,4,16,0.25,0,1,0,9,10,0.9,3,1,4,1,7,1,1,0,17,16.8
1986,6,6,3/19/1986,23,30,23.08213552,Chicago,Away,PHI,0,-6,0,15,4,14,0.286,0,2,0,4,6,0.667,4,0,4,3,2,2,1,1,12,9.9
1986,4,4,3/15/1986,23,26,23.07118412,Chicago,Home,MIL,0,-9,0,13,4,7,0.571,0,0,,4,7,0.571,0,1,1,2,1,0,1,2,12,8.4
1986,3,3,10/29/1985,22,254,22.6954141,Chicago,Away,GSW,1,6,1,18,6,10,0.6,0,0,,0,0,,0,2,2,2,0,0,1,1,12,8
1986,8,8,3/22/1986,23,33,23.09034908,Chicago,Away,CLE,0,-26,0,16,4,13,0.308,0,0,,0,1,0,1,0,1,1,0,0,1,2,8,-0.3

Привет @Fravadona, большое спасибо за усилия. Два вопроса: может ли быть сортировка наоборот? Я имею в виду более высокое значение сверху?. Другой вопрос: заголовок пропал?

Jose Antonio Piedehierro Arias 16.05.2022 22:44

@JoseAntonioPiedehierroArias возможно да, взгляните на обновление

Fravadona 16.05.2022 23:02

Тогда я должен просто изменить запись с моим именем файла, верно? RecordS() - это опечатка? должна быть запись ()?

Jose Antonio Piedehierro Arias 16.05.2022 23:11

Имя файла для замены — file.csv в конце блока { ... }. record и records — две разные переменные; первый хранит текущую строку, другой хранит все строки.

Fravadona 16.05.2022 23:15

Сортировка не в порядке, но все равно спасибо за усилия! Престижность. Если вы обнаружите проблему, пожалуйста, обновите ответ, но спасибо!

Jose Antonio Piedehierro Arias 16.05.2022 23:19

Хорошо, сортировка работает, но в первом столбце :( годы идут от самого нового к самому старому.

Jose Antonio Piedehierro Arias 16.05.2022 23:26

Я нашел ошибку, теперь она должна работать как положено

Fravadona 16.05.2022 23:38

Использование sed

$ sed -n '/^1985/!{1p;/\(\([^,]*,\)\{8\}\)0\(.*\)/s//\1Away\3/;/\(\([^,]*,\)\{8\}\)1\(.*\)/s//\1Home\3/;{/CHI/s/\(\([^,]*,\)\{7\}\)\([^,]*\)\(.*\)/\1Chicago\4/p;/WAS/s/\(\([^,]*,\)\{7\}\)\([^,]*\)\(.*\)/\1Washington\4/p}}' input_file
$ cat script.sed
/^1985/!{
    1p
    /\(\([^,]*,\)\{8\}\)0\(.*\)/s//\1Away\3/
    /\(\([^,]*,\)\{8\}\)1\(.*\)/s//\1Home\3/
    {
        /CHI/s/\(\([^,]*,\)\{7\}\)\([^,]*\)\(.*\)/\1Chicago\4/p
        /WAS/s/\(\([^,]*,\)\{7\}\)\([^,]*\)\(.*\)/\1Washington\4/p
    }
}
$ sed -nf script.sed input_file
EndYear,Rk,G,Date,Years,Days,Age,Tm,Home,Opp,Win,Diff,GS,MP,FG,FGA,FG_PCT,3P,3PA,3P_PCT,FT,FTA,FT_PCT,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc
1986,1,1,10/25/1985,22,250,22.6844627,Chicago,Home,CLE,1,1,1,39,13,26,Away.5,0,0,,3,4,0.75,3,3,6,3,3,0,3,5,29,18.7
1986,2,2,10/26/1985,22,251,22.68720055,Chicago,Home,DET,1,3,1,41,9,24,Away.375,0,0,,15,16,0.938,2,5,7,6,2,3,6,5,33,22.6
1986,3,3,10/29/1985,22,254,22.6954141,Chicago,Away,GSW,Home,6,1,18,6,10,0.6,0,0,,0,0,,0,2,2,2,0,0,1,1,12,8
1986,4,4,3/15/1986,23,26,23.07118412,Chicago,Home,MIL,Away,-9,0,13,4,7,0.571,0,0,,4,7,0.571,0,1,1,2,1,0,1,2,12,8.4
1986,5,5,3/17/1986,23,28,23.07665982,Chicago,Away,ATL,0,-10,0,Home4,4,16,0.25,0,1,0,9,10,0.9,3,1,4,1,7,1,1,0,17,16.8
1986,6,6,3/19/1986,23,30,23.08213552,Chicago,Away,PHI,0,-6,0,Home5,4,14,0.286,0,2,0,4,6,0.667,4,0,4,3,2,2,1,1,12,9.9
1986,7,7,3/21/1986,23,32,23.08761123,Chicago,Away,BOS,0,-21,0,Home6,7,16,0.438,0,1,0,6,7,0.857,2,0,2,1,0,1,1,3,20,11.8
1986,8,8,3/22/1986,23,33,23.09034908,Chicago,Away,CLE,0,-26,0,Home6,4,13,0.308,0,0,,0,1,0,1,0,1,1,0,0,1,2,8,-0.3
1986,9,9,3/25/1986,23,36,23.09856263,Chicago,Home,NYK,1,13,Away,19,5,12,0.417,0,1,0,9,9,1,1,2,3,3,1,0,2,3,19,13.8
1986,10,10,3/28/1986,23,39,23.10677618,Chicago,Away,NJN,0,-11,0,22,9,Home5,0.6,0,0,,4,6,0.667,0,1,1,3,5,0,3,4,22,17.1
1986,11,11,3/29/1986,23,40,23.10951403,Chicago,Away,NYK,Home,10,0,23,10,17,0.588,0,1,0,4,6,0.667,1,0,1,1,1,3,4,2,24,15
1986,12,12,4/1/1986,23,43,23.11772758,Chicago,Away,MIL,0,-9,0,26,8,Home6,0.5,0,1,0,12,12,1,1,4,5,2,1,3,1,2,28,24.6
1986,13,13,4/3/1986,23,45,23.12320329,Chicago,Away,IND,Home,1,0,28,12,19,0.632,0,0,,2,4,0.5,1,4,5,3,3,2,3,1,26,21.7
1986,14,14,4/5/1986,23,47,23.12867899,Chicago,Home,ATL,1,5,Away,31,10,21,0.476,2,3,0.667,8,9,0.889,1,2,3,3,1,1,4,1,30,19.6
1986,15,15,4/7/1986,23,49,23.13415469,Chicago,Home,MIL,1,6,1,31,10,18,Away.556,1,3,0.333,5,5,1,,1,3,2,3,26,24.1
1986,16,16,4/8/1986,23,50,23.13689254,Chicago,Away,ATL,0,-13,Home,33,12,25,0.48,0,2,0,6,6,1,1,5,6,6,2,1,7,2,30,18.6
1986,17,17,4/11/1986,23,53,23.14510609,Washington,Home,WSB,1,2,1,37,12,36,Away.333,0,1,0,7,10,0.7,1,4,5,2,3,1,2,5,31,12.4
1986,18,18,4/13/1986,23,55,23.15058179,Washington,Away,CLE,0,-7,Home,29,11,23,0.478,0,2,0,7,7,1,0,3,3,4,4,0,2,4,29,21.4

Другие вопросы по теме