splitting file with more than one delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting splitting file with more than one delimiter
# 1  
Old 10-06-2005
splitting file with more than one delimiter

Hi,

I just wandering how to split a record which has more than one delimiter,
i have a file which contains pattern [999]as group separtor and ~ as field separtor, Ultimately I need consider even the groups as a field, So i need to make this multi-delimited file into ~ delimited file.

My record looks like

Actual record 1
Code:
[001]XXX[002]~D~199~PASSTHRSETT~xx xx~~[003]US[004]USD[005]A[006]A[007]09-DEC-99[008]09-DEC-99[040]5[050]5[060]1[061]0[062]0[063]0[064]0

Actual record 2

Code:
[001]YYY[002]~D~199~PP~xx xx~~[003]US[004]USD[005]A[006]A[007]09-OCT-99[008]09-DEC-99[040]5[050]5[060]1[061]0[062]0[063]0[064]0


Can someone tell me, how can I split the record so that output looks like
Expected record
Code:
XXX~D~199~PASSTHRSETT~xx xx~~US~USD~A~A~09-DEC-99~09-DEC-99~5~5~1~0~0~0~0

Thanks
Brian
# 2  
Old 10-06-2005
sed 's/\[[0-9]\{,3\}\]/~/g' file > newfile.
# 3  
Old 10-06-2005
Hi,

Thanks,
could you tell me what is the significance of {,3\}, is this number of repeatition.

Anyway I modified the SED as

sed 's/\[[0-9][0-9][0-9]\]/~/g' temp > n_temp and it works
# 4  
Old 10-06-2005
Quote:
Originally Posted by braindrain
could you tell me what is the significance of {,3\}, is this number of repeatition.
That's exactly what it is.
# 5  
Old 10-06-2005
Is this number repition works in a specific version ?
In my system it works like this:
sed 's/\[[0-9]\{3\}\]/~/g'

without the comma. My system is :

SunOS MyServer 5.8 Generic_117350-26 sun4u sparc SUNW,Ultra-60
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Splitting strings based on delimiter

i have a snippet from server log delimited by forward slash. /a/b/c/d/filename i need to cut until last delimiter. So desired output should look like: /a/b/c/d can you please help? Thanks in advance. (7 Replies)
Discussion started by: alpha_1
7 Replies

2. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

3. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

4. Shell Programming and Scripting

Splitting records in a text file based on delimiter

A text file has 2 fields (Data, Filename) delimited by # as below, Data,Filename Row1 -> abc#Test1.xml Row2 -> xyz#Test2.xml Row3 -> ghi#Test3.xml The content in first field has to be written into a file where filename should be considered from second field. So from... (4 Replies)
Discussion started by: jayakkannan
4 Replies

5. Shell Programming and Scripting

Splitting number (no delimiter)

Hi ! here is my data file column 1 fields 2597 121297 13599 130498 want to print like this 02/05/1997 12/12/1997 13/05/1999 13/04/1998 how to split each field and print in correct way if there was delimiter I would have done some thing like this awk '{split($0,a,":");... (13 Replies)
Discussion started by: Akshay Hegde
13 Replies

6. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

7. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

8. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies
Login or Register to Ask a Question