Insert Delimiter at fixed locations in a flat file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Insert Delimiter at fixed locations in a flat file
# 1  
Old 06-14-2010
Data Insert Delimiter at fixed locations in a flat file

Hi

Can somebody help me with solution for this PLEASE?

I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width.

For Example
Here is the file
Code:
{
kkjhdhal
sdfewss
sdtereetyw
}

I need to divide it into 3 columns with widths 2, 3, remaining

My desired output for this file would be
Code:
{
kk;jhd;hal
sd;few;ss
sd;ter;eetyw
}

Can someone help me with command to be used please?

Thanks

Last edited by radoulov; 06-14-2010 at 04:59 PM.. Reason: Please use code tags!
# 2  
Old 06-14-2010
Code:
$ cat file
kkjhdhal
sdfewss
sdtereetyw
$ sed "s/^\(..\)\(...\)/\1;\2;/" file
kk;jhd;hal
sd;few;ss
sd;ter;eetyw

# 3  
Old 06-14-2010
Code:
sed '/{/,/}/ s/\(..\)\(...\)/\1;\2;/' infile

# 4  
Old 06-14-2010
Code:
 sed 's/\(..\)\(...\)\(.*\)/\1;\2;\3/' file
{
kk;jhd;hal
sd;few;ss
sd;ter;eetyw
}

# 5  
Old 06-14-2010
Thank you very much for responding -
$ sed "s/^\(..\)\(...\)/\1;\2;/" file

Output:
kk;2;hal
sd;2;ss
sd;2;eetyw
# 6  
Old 06-14-2010
You may be forget one backslash Smilie

Code:
# sed "s/^\(..\)\(...\)/\1;2;/" file
{
kk;2;hal
sd;2;ss
sd;2;eetyw
}

Code:
# sed "s/^\(..\)\(...\)/\1;\2;/" file
{
kk;jhd;hal
sd;few;ss
sd;ter;eetyw
}

# 7  
Old 06-16-2010
Ouch Smilie! Thanks a bunch! THank you!

Thanks All!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fixed length flat file extraction

Hii ,I am new to Unix ,i have a flat file which is (fixed length) sitting in unix,Which is holding the data for a table.I want to extract one column(length7-10) on the basis of another column(length13-15) and want only one single row Example: Below is the sample of flat file. 1111 AAAA 100 ... (4 Replies)
Discussion started by: laxmi1166
4 Replies

2. Shell Programming and Scripting

how to implement in one-line awk in a fixed file having no delimiter

Hi, I have a file a.txt having no delimiter. I want to exclude the line which contains 435th character as 1 or 2 and redirect the rest of the lines to another file b. Can you pls suggest how to do this in one liner awk. Following is just one line of the input file a:- 120110116 ... (10 Replies)
Discussion started by: millan
10 Replies

3. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

4. Shell Programming and Scripting

How to read the first column in a flat file with ~ as delimiter

I have one flat file like below id1~col~batch1 id2~col2~batch2 id3~col3~batch3 I need to read the first column one by one and I need to write one db2 query based on that column1 Like for (i=0;i<=10;i++) do insert into table column (con_id) values (select column from table where... (4 Replies)
Discussion started by: siri_886
4 Replies

5. Shell Programming and Scripting

reading fixed length flat file and calling java code using shell scripting

I am new to shell scripting and I have to to the following I have a flat file with storename(lenth 20) , emailaddress(lenth 40), location(15). There is NO delimiters in that file. Like the following str00001.txt StoreName emailaddress location... (3 Replies)
Discussion started by: willywilly
3 Replies

6. Shell Programming and Scripting

how to read fixed length flat file....

Hi Gurus, Thanks in advance... I am new to writing shell scripting and help me out reading a flat file with fixed length. I have a fixed length flat file with storename(lenth 6) , emailaddress(lenth 15), location(10). There is NO delimiters in that file. Like the following str00001.txt... (2 Replies)
Discussion started by: willywilly
2 Replies

7. Shell Programming and Scripting

Exporting a flat fixed length file (Urgent)

Hi All, So far, I've been extracting data from db2 tables and exporting the file as a tab delimited file into a UNIX server using the following command: export to /.../.../.../.../.../SM_RAW_DATA.dat of del modified by coldel| nochardel select a.accno, a.CUR_BL_AM, ... (1 Reply)
Discussion started by: jj2485
1 Replies

8. UNIX for Dummies Questions & Answers

Conditional sorting on fixed length flat file

I have a fixed length file that need to be sorted according to the following rule IF B=1 ORDER by A,B Else ORDER by A,C Input file is ABC 131 112 122 231 212 222 Output needed ABC 112 131 122 212 231 222 (1 Reply)
Discussion started by: zsk_00
1 Replies

9. Shell Programming and Scripting

How to insert at a particular position in flat file

Hi All, I have a flat file with ~ as de-limiter (e.g: aaa~ba a~caa~0~d~e) What I want is check if the 4th character is 0 and replace it with say 4. So now it becomes : aaa~ba a~caa~4~d~e. I have to do this for the whole file, but the delimiter position remains the same, not the... (10 Replies)
Discussion started by: akdwivedi
10 Replies

10. Shell Programming and Scripting

adding delimiter to a fixed width file

Hi , I have a file : CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74100.00 CSCH74100.00 I have to put a delimiter( say comma) in between after 6th character: CSCH74,000.00 CSCH74,000.00 CSCH74,100.00 (2 Replies)
Discussion started by: sumeet
2 Replies
Login or Register to Ask a Question