[Solved] shell – remove numbers from a string column [closed]


You should have been more clearer when you raise the problem. Do not add test cases later

You can try this, I have modified the third field to last but one. But credit to @Kaz

~> more test
SER1828-ZXC-A1-10002
SER1878-IOP-B1-98989
SER1930-QWE-A2-10301
SER1930-QWE-A2-10301
SER1930-QWS_GH-A2-10301
SER1930-REM_PH-A2-10301
SER1930-REM-SEW-PH-A2-10301
SER1940-REM-SPD-PL-D3-10301


~> awk -F- 'BEGIN { OFS="-" } { sub(/[0-9]/,"",$(NF-1)); print }' test
SER1828-ZXC-A-10002
SER1878-IOP-B-98989
SER1930-QWE-A-10301
SER1930-QWE-A-10301
SER1930-QWS_GH-A-10301
SER1930-REM_PH-A-10301
SER1930-REM-SEW-PH-A-10301
SER1940-REM-SPD-PL-D-10301

Edit

Explanation

-F- -> Define the input field separator 
OFS="-" ->  Set the output field separator 
sub( -> Substitute    
/[0-9]/ -> Select all the numbers 
"" -> substitute with nothing
$(NF-1) -> For the last but one field
Print -> Print All results

1

solved shell – remove numbers from a string column [closed]