Reading a FLAT File - No Delimeters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a FLAT File - No Delimeters
# 1  
Old 04-09-2010
MySQL Reading a FLAT File - No Delimeters

Hi Folks,

I have a file without any delimeters and it is a flat file. Example,

my raw data looks: x25abcy26defz27ghi.....

Now, could you please any one help me to program to split this into variable and create a text file. I want a output as below

Name Age Number
x 25 abc
Y 26 def
z 27 ghi
# 2  
Old 04-09-2010
on linux,
Code:
[ ~]$ echo 'x25abcy26defz27ghif33jjj' | sed 's/\([a-z]\)\([0-9][0-9]*\)\([a-z][a-z][a-z]\)/\1 \2 \3\n/g'
x 25 abc
y 26 def
z 27 ghi
f 33 jjj
 
[ ~]$ sed --version
GNU sed version 4.1.5


On HP UX,
Code:
/home/->echo 'x25abcy26defz27ghif33jjj' | sed 's/\([a-z]\)\([0-9][0-9]*\)\([a-z][a-z][a-z]\)/\1 \2 \3\
/g'
x 25 abc
y 26 def
z 27 ghi
f 33 jjj
 
/home/->

# 3  
Old 04-09-2010
Thanks Ankel. However, I have given only the sample data. My first column has 16 digit card number and so on. Your sed command considers for a single character wise.

Please help how to proceed.
# 4  
Old 04-09-2010
Please tell us how to differentiate Name and Number.
Else, it will not be able to parse these records

Although below code does not do the job, it should be able to point you to the right direction once you can differentiate between Name and Number. Some regular expression will be required to sort this out
Code:
echo x25abcy26defz27ghi | sed 's/\([a-zA-Z]*\)\([1-9][0-9]*\)\([a-zA-Z]*\)/\1,\2,\3\n/g'

# 5  
Old 04-09-2010
Quote:
Originally Posted by Jerald Nathan
Thanks Ankel. However, I have given only the sample data. My first column has 16 digit card number and so on. Your sed command considers for a single character wise.

Please help how to proceed.
As chihung told, you can easily modify the regexp as per your requirement. or show us the exact rule to determine how and when splitting is required.
# 6  
Old 04-09-2010
sounds like you have a 'fixed width' field records.
do you know the widths of all the fields?
# 7  
Old 04-09-2010
Ok, Here is the original record..

1-16 is digit cardno
17-33 is digit alternatecardno
34 is string
35-47 is alphanumeric..

like that it has 15 columns with 105 length. I know only the starting position and ending position of these 15 variables.

As well as the second raw without any delimeters it starts from 106 position of the file.

Let me know if you need further clarifications..

---------- Post updated at 07:30 PM ---------- Previous update was at 07:28 PM ----------

Quote:
Originally Posted by vgersh99
sounds like you have a 'fixed width' field records.
do you know the widths of all the fields?
Yes VGersh. You r right. Please verify my last reply and help me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Reading flat file content

is there any unix tools that can read the text files like through SQL queries? (ie in Hadoop, Impala DB support flat file query) (1 Reply)
Discussion started by: omykarshan
1 Replies

2. Shell Programming and Scripting

Sort file based on number of delimeters in line

Hi, Need to sort file based on the number of delimeters in the lines. cat testfile /home/oracle/testdb /home /home/oracle/testdb/newdb /home/oracle Here delimeter is "/" expected Output: /home/oracle/testdb/newdb /home/oracle/testdb /home/oracle /home (3 Replies)
Discussion started by: Sumanthsv
3 Replies

3. Shell Programming and Scripting

How to delete lines having unmatched delimeters in a file?

Hi, I have a delimited (|) file having millions of rows. Sometime the file comes with less number of delimiters than expected. In this scenario I want to delete the row having unmatched delimiters. Can anyone help me with the command to achieve this? Ex: File1.txt 8039339595113|JIMMY... (2 Replies)
Discussion started by: satyaatcgi
2 Replies

4. Shell Programming and Scripting

reading a csv file and creating a flat file

hi i have written a script for reading a csv file and creating a flat file, suggest if this script can be optimized #---------------- FILENAME="$1" SCRIPT=$(basename $0) #-----------------------------------------// function usage { echo "\nUSAGE: $THIS_SCRIPT file_to_process\n"... (3 Replies)
Discussion started by: mprakasheee
3 Replies

5. Shell Programming and Scripting

Reading XML data in a FLAT FILE

I have a requirement to read the xml file and split the files into two diffrent files in Unix shell script. Could anyone please help me out with this requirement. Sample file --------------- 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Information... (3 Replies)
Discussion started by: kmanivan82
3 Replies

6. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

7. 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

8. Shell Programming and Scripting

Parsing a file that contains 2 types of delimeters

Now that I have a file that looks something like this; 20050926 Unknown 20050926 MUREXFO 20050926 MUREXFO 20050926 MUREXFO 20050926 Unknown 20050926 KADDUSS 20050926 KADDUSS 20050926 KADDUSS 20050926 MUREXFO Is there a way in vi that I can search the file and remove any line... (2 Replies)
Discussion started by: morgadoa
2 Replies

9. Shell Programming and Scripting

Parsing a file that contains 2 types of delimeters

I am trying to write a script and failing miserably. I have a file that looks something like this; 20050924-155819;Backoffice;1037;0;DDT-TCP/IP;;0;Node 20050924-155902;Unknown;1036;0;DDT-TCP/IP;;0;Node 20050924-155922;FrontOffice;1040;5;DDT- The desired result is one file containing only... (4 Replies)
Discussion started by: morgadoa
4 Replies

10. UNIX for Dummies Questions & Answers

Paste command reading no delimeters for sun box

I use a paste command on my HP/UX which by specifying single quotation marks my output creates a fixed width file with no delimeters: paste -d '' a b > temp on the Sun box the same command recieves an error specifying no delimeters provided. Both are running ksh. (1 Reply)
Discussion started by: r1500
1 Replies
Login or Register to Ask a Question