Reading a FLAT File - No Delimeters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a FLAT File - No Delimeters
# 8  
Old 04-09-2010
Again, what about the width of the fields after 4th field?
or you only need these first four field from each 'raw' ?

Do you want something like this?

Code:
echo '12341234123412345678567856785678S881234rrrrr23E'| awk '{print substr($0,1,16),substr($0,17,16),substr($0,34,1),substr($0,35,13)}'

# 9  
Old 04-09-2010
I don't think that any solution involving "sed" reading the file directly will work because there are no linefeed characters in the file.



Code:
# Assuming fixed length records of 6 characters
cat filename|fold -w6|while read line
do
        part1=`echo "${line}"|cut -c1-1`
        part2=`echo "${line}"|cut -c2-3`
        part3=`echo "${line}"|cut -c4-6`
        echo "${part1} ${part2} ${part3}"
done

# 10  
Old 04-09-2010
Hi Anchal,

I have 15 columns and I just gave sample of 5 fields. I think you code will work for first record. But, what about the next record and so on.

Because, the file is a sequential file.
# 11  
Old 04-09-2010
Use the forum's 'Search' capability and search for 'FIELDWIDTH'.
One such thread is 'here.
# 12  
Old 04-09-2010
Easier to use cut
Code:
echo 1234567890abcdef | cut -c1-6

However, if you have a lot of record to process, you should avoid forking too many processes. Try to use awk to print per line. See this example:
Code:
echo 1234567890abcdef | awk '
{
s4_6=substr($0,4,3)
print s4_6
}'

# 13  
Old 04-09-2010
Quote:
Originally Posted by Jerald Nathan
I have 15 columns and I just gave sample of 5 fields.
Why don't you provide at least one complete, unabbreviated record followed by exactly how it should be output. Also, take a moment to consider if there are any special cases that would require special handling. If there are any, include one complete, unabbreviated record for each of them.

Please keep in mind, for future help requests, that it would have saved everyone (including yourself) a lot of time if you had done this from the start.

Regards,
Alister
# 14  
Old 04-09-2010
Well said alister. Posting the complete problem will usually lead to a quick solution - as experienced Systems Administrators know.

Btw & imho. Post #7 is gibberish. Writing software to process this data based on the (latest) information supplied is impossible.

Last edited by methyl; 04-09-2010 at 08:48 PM.. Reason: qualified sarcasm
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