Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

closed as off topic by womble, voretaq7 Jul 28 '12 at 4:20

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.