How to split a file record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split a file record
# 1  
Old 05-20-2008
How to split a file record

-Hi, I have a problem with parcing/spliting a file record into two parts and assigning the split parts to two viriables. The record is as follows:


ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb psqport uiqport twgs cedb seng grui grag hflm lmqport

The colomns are separated by few spaces. I need to assign coloms 1 thru 31 to one variable and the rest to another variable. The spacing btw the colomns should be kept intact. Any ideas? Thanks a lot for help.
# 2  
Old 05-20-2008
Code:
tmp="ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb psqport uiqport twgs cedb seng grui grag hflm lmqport"

tmp1=$(echo $tmp | cut -d" " -f1-31)

$ echo $tmp1
ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb fcsh foma fcl1 fcl2 fnav tgdb aqdb hfps hfui hfpu hfdb


tmp2=$(echo $tmp | cut -d" " -f32-)

$ echo $tmp2
psqport uiqport twgs cedb seng grui grag hflm lmqport

# 3  
Old 05-20-2008
If there are multiple spaces which should be preserved, you need to double-quote all variables.
# 4  
Old 05-20-2008
Thanks a lot. It worked great!!
# 5  
Old 05-20-2008
Era, you are right, unfortunatelly the spacing is not preserved. Can you please give me the example of how to preserve spacing between colomns. Thanks
# 6  
Old 05-20-2008
Era, can you plz give me the example, I am struggling with preserving the correct spacing. Thanks a lot for help and advice -Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to split large file with different record delimiter?

Hi, I have received a file which is 20 GB. We would like to split the file into 4 equal parts and process it to avoid memory issues. If the record delimiter is unix new line, I could use split command either with option l or b. The problem is that the line terminator is |##| How to use... (5 Replies)
Discussion started by: Ravi.K
5 Replies

2. Shell Programming and Scripting

EBCDIC File Split Based On Record Key

I was wondering if anyone could explain to me how to split a variable length EBCDIC file into seperate files based on the record key. I have the COBOL layout, and so I need to split the file into 13 different EBCDIC files so that I can run each one through a C++ converter I have, and get the... (11 Replies)
Discussion started by: hanshot1stx
11 Replies

3. Shell Programming and Scripting

Split a large file in n records and skip a particular record

Hello All, I have a large file, more than 50,000 lines, and I want to split it in even 5000 records. Which I can do using sed '1d;$d;' <filename> | awk 'NR%5000==1{x="F"++i;}{print > x}'Now I need to add one more condition that is not to break the file at 5000th record if the 5000th record... (20 Replies)
Discussion started by: ibmtech
20 Replies

4. Shell Programming and Scripting

Need to split record

Hi All, Need help in writing a shell script for the below requirement: i/p: 123456789 o/p: 123 456 789 Req: one record should be split into multiple based on the length ( after every third character it should be moved into next line) Thanks in Advance (14 Replies)
Discussion started by: HemaV
14 Replies

5. Shell Programming and Scripting

split content and write to new record

Hi, Help required to split record value and write to new row. Input a~b~c~value in ('3','4','5')~test output a~b~c~3~test a~b~c~4~test a~b~c~5~test input a~b~c~value in ('3','4')~test output a~b~c~3~test a~b~c~4~test (8 Replies)
Discussion started by: Jairaj
8 Replies

6. UNIX for Dummies Questions & Answers

split record without pattern

Hi , I have file with all records in one line, which needs to split it to have a fixed length.Am trying to execute the below script for the same FILENAME="$1" while line LINE do echo $LINE | awk 'BEGIN{n=1}{while(substr($0,n,10)){print substr($0,n,10);n+=10}}' done < $FILENAME it... (4 Replies)
Discussion started by: nishantrk
4 Replies

7. Shell Programming and Scripting

Record split.

I want to keep only records contain length is 10 other records should remove from my original file without redirecting to other output file. Source 1234567890 123456789011234 abcdefghil Expected Result 1234567890 abcdefghil (9 Replies)
Discussion started by: Jairaj
9 Replies

8. Shell Programming and Scripting

Split a record based on particular match

Hi , I have a requirement to split the record based on particular match using UNIX. Case1: Input Record : 10.44.48.63;"Personals/Dating;sports";1441 Output Records : 10.44.48.63;Personals/Dating;1441;Original 10.44.48.63;sports;1441;Dummy Case2: Input Record : ... (5 Replies)
Discussion started by: mksuneel
5 Replies

9. Shell Programming and Scripting

Split long record into csv file

Hi I receive a mainframe file which has very long records (1100 chars) with no field delimiters. I need to parse each record and output a comma delimited (csv) file. The record layout is fixed. If there weren't so many fields and records I would read the file into Excel, as a "fixed width"... (10 Replies)
Discussion started by: wvdeijk
10 Replies

10. Shell Programming and Scripting

Split a record

UNIX Scripting Hi I am trying to read a record and split it into multiple records My Record looks like this 1001A0010@B0010*&^0)C0012hgdj&6sD0020fhfri93kivmepi9 where UniqueID is 1001 segments are A,B,C,D length of each segment is 4 characters after the segment 0010 for A 0010 for B 0012... (5 Replies)
Discussion started by: pukars4u
5 Replies
Login or Register to Ask a Question