-3

I am having a list of ids (total 2 lakh), I want to write a shell script to split the ids (string and integer) using shell script . Example given below :

IDlist.txt:

   | LT345   |
   | R567    |
   | LT9     |
   | MRTD002 |
   | MK53    |
   | RR567   |

I have extracted the ids from IDlist.txt with the following script.

awk '{print $2}' IDlist.txt > newId_list.txt

newId_list.txt:

LT345   
R567    
LT9     
MRTD002 
MK53    
RR567   

How can I split the newId_list.txt ids as given below ?

result_string.txt:

LT
R
LT
MRTD
MK
RR

result_integer.txt:

345
567
9
002
53
567
mgorven
  • 30,615
  • 7
  • 79
  • 122
ara
  • 11
  • 1
  • 2

2 Answers2

1

You can use grep with the -o option to match certain characters and only output those. For example:

% grep -E -o '[A-Z]+' newId_list.txt
LT
R
LT
MRTD
MK
RR

% grep -E -o '[0-9]+' newId_list.txt
345
567
9
002
53
567

This could even be run on the orginial IDlist.txt directly.

mgorven
  • 30,615
  • 7
  • 79
  • 122
1

Another way is to use tr to remove unneeded symbols:

tr -d \|\ [:alpha:] < idlist.txt                                                                                                                                                                                 
345
567
9
002
53
567

tr -d \|\ [:digit:] < idlist.txt 
LT
R
LT
MRTD
MK
RR
DukeLion
  • 3,259
  • 1
  • 18
  • 19