Split positional flat file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split positional flat file.
# 1  
Old 08-03-2009
Split positional flat file.

Hi,

I need to split positional flat file, based on value at position 43-45.( in red "410")
Example:
12345678907886421689200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007

I tried using read line but it reduces the space and so positions get changed.

Is there any other way of doing this.

Please advice.

Thanks.

---------- Post updated at 03:35 AM ---------- Previous update was at 03:31 AM ----------

Hi,

I need to split positional flat file, based on value at position 43-45.( in red "410")
Example:
12345678907886421689 200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007


I tried using read line but it reduces the space and so positions get changed.

Is there any other way of doing this.

Please advice.

Thanks.
# 2  
Old 08-03-2009
Yes ,

It is possible. Can You post the output your expecting ?..
# 3  
Old 08-03-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 08-03-2009
can you post what you have tried too???
# 5  
Old 08-03-2009
For every "410" at position 43 to 45, I need to create new file.


for sample data shown in above post, I need 2 output files

Code:
 
First file will have following lines 
 
12345678907886421689 200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
 
and Second will have following lines
 
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007

# 6  
Old 08-03-2009
An awk will do the work :

Code:
awk ' BEGIN { c=0 }
{
if(substr($0,34,3)=="410")
{
c++;
print >> "File_" c ; next ;
}
else
{
print >> "File_" c;
}
}'  input_file.txt

according to the Data you posted Position of "410" is at 34-36.
# 7  
Old 08-03-2009
Thanks panyam. This is working. Thanks alot.


Quote:
Originally Posted by panyam
An awk will do the work :

Code:
awk ' BEGIN { c=0 }
{
if(substr($0,34,3)=="410")
{
c++;
print >> "File_" c ; next ;
}
else
{
print >> "File_" c;
}
}'  input_file.txt

according to the Data you posted Position of "410" is at 34-36.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file based on positional constraints

I have a list file1 like dog cow fox cat fish duck crowI want to classify the elements of file1 based on constrains applied on file2. Additionally the number of elements (words) in the each line of file2 is not fixed. This is my file2 cow cat fox dog cow fox dog fish crow fox dog cat ... (5 Replies)
Discussion started by: sammy777
5 Replies

2. Shell Programming and Scripting

Positional Update of XML File

Hello, I have a XML file and need to update the data for a specific XML Attribute in the file. I need a Perl or Awk command to look for <INTERCHANGE_CONTROL_NO>000000601</INTERCHANGE_CONTROL_NO> in the XML file and change the first two 0 of the value to 9. For instance ... (4 Replies)
Discussion started by: Praveenkulkarni
4 Replies

3. UNIX for Dummies Questions & Answers

Remove lines in a positional file based on string value

Gurus, I am relatively new to Unix scripting and am struck with a problem in my script. I have positional input file which has a FLAG indicator in at position 11 in every record of the file. If the Flag has value =Y, then the record from the input needs to be written to a new file.However if... (3 Replies)
Discussion started by: gsam
3 Replies

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

5. Shell Programming and Scripting

Get the positional value from first line of the file

Hi, I have one flat file with delimited field as pipe(|) symbol. The file contains header,detail lines. Header is the first line in the file. I want to read the value for the position from 15 to 18 in first line of the file. Pls help me to get the value from position 15 to 18 in... (3 Replies)
Discussion started by: praka
3 Replies

6. Programming

compare XML/flat file with UNIX file system structure

Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Discussion started by: shafi2all
6 Replies

7. Shell Programming and Scripting

Flat file

Hi I have a flat file looking this QWER 2:35 7044 00001 ROUT 1188 EA SS ASD 2:36 7044 00010 ROUT BSD 2:37 7044 00011 ROUT END QWER 3:35 7044 00011 ROUT 1088 EA SS ASD 3:36 7044 00010 ROUT BSD 3:37 7044 00011 ROUT... (9 Replies)
Discussion started by: Krishnaramjis
9 Replies

8. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

9. Shell Programming and Scripting

Perl : split flat line's to $

Hi, below is the software list of lines I have, MozillaSrc 1.7.8.00.00 Mozilla 1.78 Source Distribution NFS B.11.11 ONC/NFS; Network-File System,Information Services,Utilities NParProvider B.11.11.01.04.01.01 nPartition Provider NPartition ... (7 Replies)
Discussion started by: acomd2
7 Replies

10. Shell Programming and Scripting

Help with a Flat File!!!

Hi All, I need a help with a shelll script program.I get a '|' separated file which sometime has a encrypted column.And this encryption sometime breaks the last column data into a new line and this is not picked by the ETL.So when i run a script,it should append back the broken new line data... (11 Replies)
Discussion started by: kumarsaravana_s
11 Replies
Login or Register to Ask a Question