首頁>Linux>source

我想將所有以" United"開頭的国家/地區的驅動程式名稱大寫 "。

例如:

来自

20  [United Kingdom] Nigel Mansell                 188 31

20  [United Kingdom] NIGEL MANSELL                 188 31

我正在使用的命令:

cat f1.txt | sed -r 's/[^ ]"United"\s+[A-Z]+[a-z]*]\s+[A-Z]+[a-z]*\s+[A-Z]+[a-z]*-?[A-Z]?+[a-z]?*/\U&/g'

完整列表:

Rank Country         Driver                      Races Wins
1   [United Kingdom] Lewis Hamilton                264 94
3   [Spain] Fernando Alonso                        311 32
8   [United Kingdom] Jenson Button                 306 15
11  [Netherlands] Max Verstappen                   116 9
17  [United Kingdom] David Coulthard               246 13
20  [United Kingdom] Nigel Mansell                 188 31
26  [United Kingdom] Jackie Stewart                100 27
27  [United Kingdom] Damon Hill                    115 22
28  [Spain] Carlos Sainz Jr.                       115 0
32  [United Kingdom] Graham Hill                   177 14
37  [United Kingdom] Jim Clark                     72  25
38  [Poland] Robert Kubica                         97  1
41  [South Africa] Jody Scheckter                  112 10
42  [New Zealand] Denny Hulme                      112 8
47  [Switzerland] Clay Regazzoni                   131 5
49  [Sweden] Ronnie Peterson                       123 10
50  [New Zealand] Bruce McLaren                    102 4
51  [Russian Federation] Daniil Kvyat              107 0
52  [United Kingdom] Eddie Irvine                  147 4
54  [United Kingdom] Stirling Moss                 72  16
58  [United Kingdom] John Surtees                  111 6
59  [United States] Mario Andretti                 128 12
60  [United Kingdom] James Hunt                    92  10
63  [United Kingdom] John Watson                   152 5
64  [Thailand] Alexander Albon                     35  0
69  [United States] Dan Gurney                     86  4
71  [United Kingdom] Mike Hawthorn                 48  3
76  [United Kingdom] Lando Norris                  35  0
78  [United Kingdom] Paul di Resta                 59  0
80  [United States] Richie Ginther                 52  1
85  [United States] Phil Hill                      51  3
86  [United Kingdom] Martin Brundle                158 0
87  [United Kingdom] Johnny Herbert                161 3
89  [Sweden] Stefan Johansson                      79  0
90  [New Zealand] Chris Amon                       97  0
94  [United Kingdom] Tony Brooks                   41  6
95  [Venezuela] Pastor Maldonado                   95  1
99  [United Kingdom] Derek Warwick                 147 0
100 [United States] Eddie Cheever                  132 0
101 [Switzerland] Jo Siffert                       97  2
103 [Russian Federation] Vitaly Petrov             57  0
104 [United Kingdom] Peter Revson                  30  2
113 [United Kingdom] Peter Collins                 36  3
114 [United Kingdom] Innes Ireland                 52  1
119 [Sweden] Jo Bonnier                            106 1
120 [Spain] Pedro de la Rosa                       105 0
124 [United Kingdom] Mark Blundell                 61  0
125 [United States] Harry Schell                   63  0
127 [Sweden] Gunnar Nilsson                        31  1
128 [Spain] Jaime Alguersuari                      46  0
130 [United States] Jim Rathmann                   12  1
132 [United Kingdom] Mike Hailwood                 51  0
133 [Switzerland] Sebastien Buemi                  55  0
135 [United Kingdom] Mike Spence                   36  0
136 [South Africa] Tony Maggs                      26  0
140 [United States] Masten Gregory                 40  0
142 [United States] Sam Hanks                      9   1
143 [United Kingdom] Piers Courage                 27  0
145 [United States] Bill Vukovich                  5   2
147 [United Kingdom] Tom Pryce                     42  0
148 [United Kingdom] Roy Salvadori                 48  0
149 [United States] Jimmy Bryan                    9   1
153 [Sweden] Marcus Ericsson                       97  0
159 [Switzerland] Marc Surer                       82  0
160 [Netherlands] Jos Verstappen                   106 0
161 [United Kingdom] Stuart Lewis-Evans            14  0
167 [United Kingdom] Mike Parkes                   6   0
168 [United States] Rodger Ward                    12  1
174 [United Kingdom] Jonathan Palmer               84  0
176 [Sweden] Reine Wisell                          23  0
179 [United Kingdom] Jackie Oliver                 50  0
180 [United States] Johnnie Parsons                10  1
181 [United Kingdom] Peter Arundell                13  0
185 [United States] Tony Bettenhausen              13  0
186 [United Kingdom] Cliff Allison                 16  0
187 [United Kingdom] Richard Attwood               17  0
188 [United Kingdom] Peter Gethin                  30  1
191 [Switzerland] Rudi Fischer                     7   0
192 [United States] Johnny Thomson                 9   0
194 [New Zealand] Howden Ganley                    36  0
199 [United States] Troy Ruttman                   8   1
200 [United States] Lee Wallard                    2   1
最新回復
  • 6月前
    1 #

    您正在做的太過分了,請利用檔案結構来簡化它!

    如果我们找到字元串 [United 在一行中,將大括號(从右括號到该行的末尾)全部大寫,可以得到您想要的結果.將其翻译成Sed語言,

    sed '/\[United/s/].*/\U&/' file
    

    請註意,以上內容特定於GNU Sed.如果不可用,但在POSIX系統中,則可以使用具有類似語法的Ex(或查看αғsнιη的Awk版本):

    printf '%s\n' 'g/\[United/s/].*/\U&/' '%p' | ex file
    

    要儲存對檔案的更改而不是print結果,請更改 %px

  • 6月前
    2 #

    使用 awk

    awk -F"[][]" '$2 ~/^United/ { $2="["$2"]"; $3=toupper($3); }1' OFS='' infile
    

    [...]內 我们定義了两个 和 ] 作為欄位分隔符,然後檢查第二个欄位是否以 [開頭 文字,如果是,則添加迴 United 大約在第二场提交(我认為没有其他列会倾斜這些字元,否則這些欄位將丢失此欄位); 然後將第三列轉換為其大寫值; 成語 [] 是觸發器 1 預設print(一種始终為真的條件)。

    awk

  • debugging:如何修補Debian軟體包?
  • zsh:如何將文字檔案的每一行寫入新檔案並根据其內容命名?