Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Need script for making files based on some conditions.

$
0
0
Hi All,

I have a text file (code_data.txt) with the followig data.
Code:

AMAR    AB123456                  XYZ
KIRAN    CB789                        ABC
RAJ      CS78890                      XYZ
KAMESH  A33535335                ABC
KUMAR    MD678894                  MAT
RITESH  SR3535355                  SAB
RAHUL    PM366536666              SAS
RAMANA  KS566767477747        ABC
DINESH  SA6666464664646        SAB
SUJAN    GD6674474747              SAS
SOM      MD6546474777              XYZ
GANE    MS657869933553666747  XYZ

I have to make three files using this file (code_data.txt) based on the below conditions.

The records which belongs to the code "XYZ" should be in one file,
the records which belongs to the code "ABC" should be in one file
and remaining records which belongs to all other codes should be in one file.

In the target three files we should exclude the code.

The expected files should be as below.

Code:

file1_XYZ

AMAR    AB123456             
RAJ      CS78890               
SOM      MD6546474777         
GANE    MS657869933553666747 

file2_ABC

KIRAN    CB789                 
KAMESH  A33535335             
RAMANA  KS566767477747       

file3_REM

KUMAR    MD678894             
RITESH  SR3535355             
RAHUL    PM366536666           
DINESH  SA6666464664646       
SUJAN    GD6674474747

Please help me.

Thanks in advance.

Viewing all articles
Browse latest Browse all 16232

Trending Articles