Visit Our UNIX and Linux User Community


Split a record based on particular match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split a record based on particular match
# 1  
Old 11-23-2010
Java Split a record based on particular match

Hi ,
I have a requirement to split the record based on particular match using UNIX.

Case1:

Input Record :
Code:
10.44.48.63;"Personals/Dating;sports";1441

Output Records :
Code:
10.44.48.63;Personals/Dating;1441;Original
10.44.48.63;sports;1441;Dummy

Case2:
Input Record :
Code:
10.44.48.63;"Personals/Dating;sports;zupiter";1441

Output Records :
Code:
10.44.48.63;Personals/Dating;1441;Original
10.44.48.63;sports;1441;Dummy
10.44.48.63;zupiter;1441;Dummy

Case3:
Input record :
Code:
10.44.48.63;"Personals/Dating";1441

Output record :
Code:
10.44.48.63;Personals/Dating;1441;Origonal

Can some one help me Smilie

Regards,
MKS

Last edited by Franklin52; 11-23-2010 at 03:57 AM.. Reason: Please use code tags
# 2  
Old 11-23-2010
Try...

Code:
 
awk -F\" '{k=split($2,arr,";")
for(i=1;i<=k;i++)
 if(i==1)
   print $1,arr[i],$NF";Original"
  else
   print $1,arr[i],$NF";Dummy"}' infile

# 3  
Old 11-23-2010
Try:
Code:
perl -nle 's/"//g;/^([^;]+);(.*);([^;]+)$/;$,=";";$i=0;map {print $1,$_,$3,($i)?"Dummy":"Original";$i=1} split /;/,$2' file

# 4  
Old 11-23-2010
Thanks a lot Malcom...

But in the O/P I am getting spaces like the below

10.44.48.63; Personals/Dating ;1441;Original
10.44.48.63; sports ;1441;Dummy

Many Thanks,
MKS
# 5  
Old 11-23-2010
Code:
 
awk -F\" '{k=split($2,arr,";")
for(i=1;i<=k;i++)
 if(i==1)
   print $1,arr[i],$NF";Original"
  else
   print $1,arr[i],$NF";Dummy"}' OFS="" infile

# 6  
Old 11-23-2010
Code:
awk -F";" '{gsub(/"/,"");print $1,$2,$NF,"Original";
                for (i=3;i<NF;i++) print $1,$i,$NF,"Dummy"
               }' OFS=";" infile


Previous Thread | Next Thread
Test Your Knowledge in Computers #214
Difficulty: Easy
Cisco Internetwork Operating System (IOS) is a family of network operating systems used on many Cisco Systems routers and current Cisco network switches originally designed by Sun Microsystems.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

EBCDIC File Split Based On Record Key

I was wondering if anyone could explain to me how to split a variable length EBCDIC file into seperate files based on the record key. I have the COBOL layout, and so I need to split the file into 13 different EBCDIC files so that I can run each one through a C++ converter I have, and get the... (11 Replies)
Discussion started by: hanshot1stx
11 Replies

4. Shell Programming and Scripting

Need to split record

Hi All, Need help in writing a shell script for the below requirement: i/p: 123456789 o/p: 123 456 789 Req: one record should be split into multiple based on the length ( after every third character it should be moved into next line) Thanks in Advance (14 Replies)
Discussion started by: HemaV
14 Replies

5. Shell Programming and Scripting

Help needed - Split large file into smaller files based on pattern match

Help needed urgently please. I have a large file - a few hundred thousand lines. Sample CP START ACCOUNT 1234556 name 1 CP END ACCOUNT CP START ACCOUNT 2224444 name 1 CP END ACCOUNT CP START ACCOUNT 333344444 name 1 CP END ACCOUNT I need to split this file each time "CP START... (7 Replies)
Discussion started by: frustrated1
7 Replies

6. UNIX for Dummies Questions & Answers

split record without pattern

Hi , I have file with all records in one line, which needs to split it to have a fixed length.Am trying to execute the below script for the same FILENAME="$1" while line LINE do echo $LINE | awk 'BEGIN{n=1}{while(substr($0,n,10)){print substr($0,n,10);n+=10}}' done < $FILENAME it... (4 Replies)
Discussion started by: nishantrk
4 Replies

7. Shell Programming and Scripting

split record based on delimiter

Hi, My inputfile contains field separaer is ^. 12^inms^ 13^fakdks^ssk^s3 23^avsd^ 13^fakdks^ssk^a4 I wanted to print only 2 delimiter occurence i.e 12^inms^ 23^avsd^ (4 Replies)
Discussion started by: Jairaj
4 Replies

8. Shell Programming and Scripting

Record split.

I want to keep only records contain length is 10 other records should remove from my original file without redirecting to other output file. Source 1234567890 123456789011234 abcdefghil Expected Result 1234567890 abcdefghil (9 Replies)
Discussion started by: Jairaj
9 Replies

9. Shell Programming and Scripting

How to split a file record

-Hi, I have a problem with parcing/spliting a file record into two parts and assigning the split parts to two viriables. The record is as follows: ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb ... (5 Replies)
Discussion started by: aoussenko
5 Replies

10. Shell Programming and Scripting

Split a record

UNIX Scripting Hi I am trying to read a record and split it into multiple records My Record looks like this 1001A0010@B0010*&^0)C0012hgdj&6sD0020fhfri93kivmepi9 where UniqueID is 1001 segments are A,B,C,D length of each segment is 4 characters after the segment 0010 for A 0010 for B 0012... (5 Replies)
Discussion started by: pukars4u
5 Replies

Featured Tech Videos