Sponsored Content
Operating Systems Linux Red Hat Converting fixed width file to pipe delimiter in Linux(red-hat) Post 302934383 by Don Cragun on Friday 6th of February 2015 12:34:33 PM
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).
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
euclen(3C)						   Standard C Library Functions 						euclen(3C)

NAME
euclen, euccol, eucscol - get byte length and display width of EUC characters SYNOPSIS
#include <euc.h> int euclen(const unsigned char *s); int euccol(const unsigned char *s); int eucscol(const unsigned char *str); DESCRIPTION
The euclen() function returns the length in bytes of the Extended Unix Code (EUC) character pointed to by s, including single-shift charac- ters, if present. The euccol() function returns the screen column width of the EUC character pointed to by s. The eucscol() function returns the screen column width of the EUC string pointed to by str. For the euclen() and euccol(), functions, s points to the first byte of the character. This byte is examined to determine its codeset. The character type table for the current locale is used for codeset byte length and display width information. USAGE
These functions will work only with EUC locales. These functions can be used safely in multithreaded applications, as long as setlocale(3C) is not called to change the locale. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |MT-Level |MT-Safe with exceptions | +-----------------------------+-----------------------------+ SEE ALSO
getwidth(3C), setlocale(3C), attributes(5) SunOS 5.10 20 Dec 1996 euclen(3C)
All times are GMT -4. The time now is 10:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy