Converting fixed width file to pipe delimiter in Linux(red-hat)


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Converting fixed width file to pipe delimiter in Linux(red-hat)
# 8  
Old 02-06-2015
In a correctly working awk utility, length($0) returns the number of (single-byte or multi-byte) characters in that line (not including the terminating <newline> character).

In some (buggy) awk utilities, length($0) returns the number of bytes in that line (not including the terminating <newline> character). On these systems, substr(string, start, count) may return a substring of string that is unusable because it does not start and/or end on a character boundary.

On a correctly working awk when using a locale based on a UTF-8 codeset, the command:
Code:
awk 'BEGIN{print "Vía", length("Vía");print "Via", length("Via")}'

will print:
Code:
Vía 3
Via 3

while a buggy version might print:
Code:
Vía 4
Via 3

Note also that fixed length lines can, mean several things: Fixed number of characters per line and fixed number of bytes per line are the most common two meanings. In ASCII and other single-byte/character codesets, a fixed number of characters per line and a fixed number of bytes per line happen to be the same thing. With codesets like UTF-8, a character can be represented by one to six bytes. You can also have a fixed number of display columns per line which can be different from both of the above with some characters even having a variable width (such as <tab> typically takes 1 to 8 display columns but can be even more depending on how tab stops are set). And, on displays with proportional width fonts, every character can have a different (and sometimes variable) column width (both for characters like <tab> and due to kerning effects).
# 9  
Old 02-10-2015
Hi RudiC,

somehow your solution is resolved issue but i am not able to accommodate your solution in my code could you help on this as code in my 1st post.

Thanks..
# 10  
Old 02-10-2015
Not sure about what your request is. If it has to do with the error on Linux, please attach a reasonable part of your input file to your next post. If not, state more precisely what you're after.
# 11  
Old 02-10-2015
Hi RudiC,
Please find the script and the data file in attachments which i have changed from fixed width to pipe delimiter.
I have execute this script as below command:
awk -f split_files.awk Z1GALILEO-ZOR-RECV

change the extension of the file due to facing issue while uploading the attachments.
# 12  
Old 02-10-2015
Your script works out of the box and yields
Code:
H7216152960|70R865931021|70  |999| OPN ID69                               |20141117171817|T1|ZOR |700016901 |4791032964                                    |BVOM.ES@HP.COM         
D70R865931021|0100|  01|  |AJ716B              |000010| PGI TP25                                                   |      48|      48|       0|        |4856|1Y|8OCZ|ZB04|8O00|952|
A70R865931021|0100|  01|TB-ADV  |  |        |        |0001|        
A70R865931021|0100|  01|20141125|  |20141125|20141204|0002|      48
D70R865931021|0200|  01|  |HA115A1             |000020| OPN                                                        |       1|       1|       0|        |5060|UW|7000|ZTDI|    |000|
D
etc.

, no errors. Your input file has some locale-dependent chars in it, though:
Code:
file /tmp/Z1GALILEO-ZOR-RECV.txt 
/tmp/Z1GALILEO-ZOR-RECV.txt: ISO-8859 text, with very long lines

You might want to eliminate/convert those with e.g. iconv or recode.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing strings from file using awr Linux Red Hat

Hi experts, I have a file "salida_test" containing (in repetitive way): Point ID 1.750251 Point Name >BRI_4L_SA2__INT Interruptor 33kV Parque Industrial < value 2 Time of last value update (ascii): >03/07/17 11:11:14.596 ART< TLQ 0000000c00004000 station #79 ... (6 Replies)
Discussion started by: carlino70
6 Replies

2. Shell Programming and Scripting

Alter Fixed Width File

Thank u so much .Its working fine as expected. ---------- Post updated at 03:41 PM ---------- Previous update was at 01:46 PM ---------- I need one more help. I have another file(fixed length) that will get negative value (ex:-00000000003000) in postion (98 - 112) then i have to... (6 Replies)
Discussion started by: vinus
6 Replies

3. UNIX for Dummies Questions & Answers

Length of a fixed width file

I have a fixed width file of length 53. when is try to get the lengh of the record of that file i get 2 different answers. awk '{print length;exit}' <File_name> The above code gives me length 50. wc -L <File_name> The above code gives me length 53. Please clarify on... (2 Replies)
Discussion started by: Amrutha24
2 Replies

4. Shell Programming and Scripting

Directory / File changes on CIFS share mounted on Red Hat Linux

I have a requirement to copy the changed file on CIFS share mounted on Red Hat Linux to a remote FTP/SFTP server. I tried inotify-tools, but this didn't track the modified files. Has anyone tried incron or any other suggestion? (1 Reply)
Discussion started by: SupeAlok
1 Replies

5. Homework & Coursework Questions

File transfer from Red Hat Linux to Windows 7

My assignment is to use C++ to generate a table of values for the U.S. standard atmosphere, when data at sea level are given, which i have done perfectly. Now, i am attempting to create a matlab script to read and plot the data. I forgot to put my table of data on my thumb drive yesterday, and... (4 Replies)
Discussion started by: ds7202
4 Replies

6. UNIX for Dummies Questions & Answers

cleaning up spaces from fixed width file while converting to csv file

Open to a sed/awk/or perl alternative so that i can stick command into my bash script. This is a problem I resolve using a combination of cut commands - but that is getting convoluted. So would really appreciate it if someone could provide a better solution which basically replaces all... (3 Replies)
Discussion started by: svn
3 Replies

7. UNIX Desktop Questions & Answers

Help with Fixed width File Parsing

I am trying to parse a Fixed width file with data as below. I am trying to assign column values from each record to variables. When I parse the data, the spaces in all coumns are dropped. I would like to retain the spaces as part of the dat stored in the variables. Any help is appreciated. I... (4 Replies)
Discussion started by: sate911
4 Replies

8. UNIX for Advanced & Expert Users

Converting field into fixed width csv

Hi I have a file having record as - 1,aaa,a123,a I need this converted to as 2nd col to 5 chars wide & 3rd col to 6chars wide such as - 1,aaa ,a123 ,a How we could achieve this? Thx in advance. (1 Reply)
Discussion started by: videsh77
1 Replies

9. Shell Programming and Scripting

Converting a Delimited File to Fixed width file

Hi, I have a delimited file generated by a database and i need to convert it to fixed width file using the field length of the database. Can any body suggest me how can i proceed with it? :confused: Thanks Raghavan (2 Replies)
Discussion started by: raghavan.aero
2 Replies

10. Shell Programming and Scripting

adding delimiter to a fixed width file

Hi , I have a file : CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74100.00 CSCH74100.00 I have to put a delimiter( say comma) in between after 6th character: CSCH74,000.00 CSCH74,000.00 CSCH74,100.00 (2 Replies)
Discussion started by: sumeet
2 Replies
Login or Register to Ask a Question