Convert variable length record to fixed length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert variable length record to fixed length
# 1  
Old 05-02-2017
Convert variable length record to fixed length

Hi Team,

I have an issue to split the file which is having special chracter(German Char) using awk command.

I have a different length records in a file. I am separating the files based on the length using awk command.

The command is working fine if the record is not having any special(German) characters and it's not working if a record contains German character.

Below is the example command which we are using to separate the file based on the length

Code:
awk '{if(length($0) == 67) { print $0 }}' Rec_Length_Test.txt > 67.txt

Please let us know how to handle German characters using awk command.

Thanks in Advance.

Thanks,
Anthuvan J.

Last edited by Scrutinizer; 05-02-2017 at 12:21 PM.. Reason: code tags
# 2  
Old 05-02-2017
Code:
 sed -n -r '/^.{67}$/p' infile

or something like:
Code:
perl -pe 'while(<>) {print $_ if $_ =~ /^.{67}$/};' < infile


Last edited by rdrtx1; 05-02-2017 at 05:08 PM..
# 3  
Old 05-02-2017
Hi rdrtx

Still I am facing the same issue. It's not working if the file is having special character(German Character).

Thanks,
Anthuvan J.
# 4  
Old 05-02-2017
Please post a few lines of the file that include the characters.
# 5  
Old 05-02-2017
  • What is your OS and version?
  • Are you using the right locale?
  • If a POSIX awk is using the right locale and length is not working correctly, then it is broken. It should report the number of characters, not the number of bytes. Reasonably recent GNU awk (3.1.8) reports it correctly..
# 6  
Old 05-03-2017
Hi,

I have posted some lines

Code:
12345678X                                            X01        AB01  01             000000000000            12345678SIERINGJA   04                      0012  0000045433AB                     VZE UXXXXXXX                                                                                                                              ERLANGEN                                                                                                                     91012        D                POSTFACH 2xxx                                                                                                    
12345678X                                            X01        AB01  01             000000000000            12345678SIERINGJA   01                      0012  0000045434AB                     STADT LAATZEN                                                                                                                               LAATZEN                                                                                                                      30880        D                MXXXXPLATZ 13                                                                                                    
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  01                      0012  0000004000AB                     WEEK MXXX CXXXXXXXXX GMBH                                                                                                                     LEIPZIG                                                                                                                      04105        D                Exxxx Wxxxxxxx PLATZ 3 - 4                                                                                        
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  01                      0012  0000004002AB                     PXXXXXXX GMBH                      C/O FXXXX AG U. CO. KG, BETRIEBSRES                                   LF                                 ESSLINGEN                                                                                                                    73734        D                RXXXXXSTR. 82                                                                                                    
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  01                      0012  0000004003AB                     HXXXXXXXX GROUP EG                                                                                                                          MANNHEIM                                                                                                                     68219        D                                                                                                                                 
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  01                      0012  0000004005AB                     HOTELBETRIEBSGESELLSCHAFT          SXXXXXXXXX MBH                                                                                            BAD WOERISHOFEN                                                                                                              86825        D                HXXXXXXXX-AXXX-STRASSE 11                                                                                          
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  01                      0012  0000004006AB                     ALLGEMEINE GEBÄUABREINIGUNG                                                                                                                 BERLIN                                                                                                                       12103        D                MXXXXXXXXXXSTRASSE 65                                                                                             
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  03                      0012  0000004007AB                     GXXX / Pxxxxxxxx GRUPPE BSC                                                                                                                 DÜREN                                                                                                                        52353        D                Oxxx-Bxxxxxxxx-STRASSE 21                                                                                          
12345678X                           16P16V61 42      X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  02                      0012  0000004008AB                     AXXX HXXX HAUS GMBH                                                                                                                         STUTTGART                                                                                                                    70374        D                Fxxxxxxxxxxxx STRAßE                                                                                                
12345678X                                            X01        AB01  01    ABC      000000000000            12345678SAUNABRSBR  04                      0012  0000004011AB                     SERVAL GEBÄUABMANAGEMENT                                                                                                                    ZWICKAU                                                                                                                      08056        D

Moderator's Comments:
Mod Comment
Please wrap all code, data, files, input & output/errors in CODE tags.
It makes it easier to read, uses fixed-width font and preserves multiple spacing for indenting or fixed width data.



Moderator's Comments:
Mod Comment Pretty sure you DON'T want to publish your customers' data in here. Take the time to obfuscate ... did it for you this time

Last edited by RudiC; 05-03-2017 at 12:11 PM.. Reason: Added CODE tags
# 7  
Old 05-03-2017
Please reconsider publishing clear text customer data in here.

From what I see in your post / attachment, ALL lines have 601 characters, and ALL umlaut chars are represented by one single byte. Mayhap some strange MS windows char set? So, the problem can't be reproduced on this side.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add substring in a file containing fixed length record.

I am new to awk and writing a script using awk. I have file containing fixed length records, I wish to extract 2 substring(each substring is padded with zeros on left e.g 000000003623) and add each substring respectively for every record in the file to get total sum of respective substring for all... (5 Replies)
Discussion started by: Devesh5683
5 Replies

2. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

3. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

4. Shell Programming and Scripting

search and replace fixed length record file

Hi I need to be search a file of fixed length records and when I hit a particular record that match a search string, substitute a known position field In the example file below FHEAD000000000120090806143011 THEAD0000000002Y0000000012 P00000000000000001234 TTAIL0000000003... (0 Replies)
Discussion started by: nedkelly007
0 Replies

5. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

6. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

7. Shell Programming and Scripting

convert fixed length file to CSV

Newbie Looking for a script to convert my input file to delimited text file. Not familier with AWK or shell programing. Below is sample record in my input file and the expected output format. My OS is HPUX 11.23. Thanks in advance for your assistance. tbtbs input file:... (12 Replies)
Discussion started by: tbtbs
12 Replies

8. Shell Programming and Scripting

fixed record length

hello! I have a file with fixed record length... format: 123445asdfg 4343777 sfgg I wanna convert it to 123445,asdfg ,4343,777 ,sfgg is there any way to do it? sed/grep/awk?? at the moment I use sed -e 's_ \(\)_,\1_g' but it works only if there are spaces between... (16 Replies)
Discussion started by: george_
16 Replies

9. Shell Programming and Scripting

Convert delimited to fixed length

Hi, I have to change a tab delimited file to a fixed length file. For text fields I need to left justify and NULL fill to the right and for number fields I need to right justify and zero fill to the left. If there are spaces between words in a text field I need to keep them as spaces. I am using... (14 Replies)
Discussion started by: nelson553011
14 Replies

10. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question