Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Convert a fixed width file to a delimited file Post 303037094 by wisecracker on Tuesday 23rd of July 2019 06:52:52 AM
Old 07-23-2019
The phrase is important!
"""any given character delimited"""
I read this as ANY character of ASCII, UNICODE or binary!

An assumption that the delimiter is any printable ASCII character was not even in my thoughts.
So until the OP clarifies what "any given character delimited" is then we have to assume the "0x00" and "0x80 to 0xFF" characters might be wanted, removed or replaced.
Code:
Last login: Tue Jul 23 11:22:27 on ttys000
AMIGA:amiga~> text="A delimited"$'\x80'"text file."$'\x80'
AMIGA:amiga~> byte=$'\x80'
AMIGA:amiga~> sed 's/\'"${byte}"'\+/&\n/g' <<< "${text}"
sed: 1: "s/\?\+/&\n/g": RE error: illegal byte sequence
AMIGA:amiga~> tr -s ${byte} ' ' <<< "${text}"
tr: Illegal byte sequence
AMIGA:amiga~> _


Last edited by wisecracker; 07-23-2019 at 09:20 AM.. Reason: Remove typo and add "or replaced"
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

how to convert Fixed length file to delimited file.

I have below fixed lenth file . I have to convert this to delimitted file. File1.txtE116005/29/19930E001E000 E12201/23/19940E001E003 E10406/4/19940E001E003 I want to convert this to : E116,0,05/29/1993,0,E001,E000 E122,0,1/23/1994,0,E001,E003 E104,0,6/4/1994,0,E001,E003 I have a... (7 Replies)
Discussion started by: satyam_sat
7 Replies

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

4. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 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. UNIX for Dummies Questions & Answers

Delete header row and reformat from tab delimited to fixed width

Hello gurus, I have a file in a tab delimited format and a header row. I need a code to delete the header in the file, and convert the file to a fixed width format, with all the columns aligned. Below is a sample of the file:... (4 Replies)
Discussion started by: chumsky
4 Replies

7. UNIX for Dummies Questions & Answers

convert # delimited text file to fixed width

Hello gurus, I have a file containing 5 columns delimited by '#' as shown in the example below: HRP1000-PLVAR#HRP1000-OTYPE#HRP1000-OBJID#HRP1000-BEGDA#HRP1000-ENDDA# 99991231#AU7129#000000000#1 PROCTER & GAMBLE# 99991231#TT4283#1000013883#21111 LAUNDRY# 99991231#TT4283#1000013884#21121 DISH... (3 Replies)
Discussion started by: chumsky
3 Replies

8. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

9. Shell Programming and Scripting

Remove new line character and add space to convert into fixed width file

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file. If the length is less than the max length, the spaces should be appended... (4 Replies)
Discussion started by: Amrutha24
4 Replies

10. 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
vis(1)							      General Commands Manual							    vis(1)

NAME
vis, inv - make unprintable and non-ASCII characters in a file visible or invisible SYNOPSIS
file ... file ... DESCRIPTION
reads characters from each file in sequence and writes them to the standard output, converting those that are not printable or not ASCII into a visible form. inv performs the inverse function, reading printable characters from each file, returning them to non-printable or non-ASCII form, if appropriate, then writing them to standard output; Non-printable ASCII characters are represented using C-like escape conventions: backslash backspace escape form-feed new-line carriage return space horizontal tab vertical tab the character whose ASCII code is the 3-digit octal number n. the character whose ASCII code is the 2-digit hexadecimal number n. Non-ASCII single- or multi-byte characters are examined one byte at a time. For each byte, if it can be displayed as an ASCII character, it is treated as if it is an ASCII character; Otherwise, it is represented in the following conventions: the 8-bit character whose code value is the 3-digit octal number n. the 8-bit character whose code value is the 2-digit hexadecimal number n. Space, horizontal-tab, and new-line characters can be treated as printable (and therefore passed unaltered to the output) or non-printable depending on the options selected. Backslash, although printable, is expanded by vis, to a pair of backslashes so that when they are passed back through inv, they convert back to a single backslash. If no input file is given, or if the argument is encountered, and inv read from the standard input. Options and recognize the following options: Treat new-line, space, and horizontal tab as non-printable characters. expands them visibly as and rather than passing them directly to the output. discards these characters, expecting only the printable expansions. New-line characters are inserted by every 16 bytes so that the output will be in a form that is usable by most editors. Make and silent about non-existent files, identical input and output, and write errors. Normally, no input file can be the same as the output file unless it is a special file. Treat horizontal-tab and space characters as non-printable in the same manner that treats them. Cause output to be unbuffered (byte-by-byte); normally, output is buffered. Cause output to be in hexadecimal form rather than the default octal form. Either form is accepted to as input. EXTERNAL INFLUENCES
Environment Variables determines the language in which messages are displayed. International Code Set Support Single- and multi-byte character code sets are supported. WARNINGS
Redirecting output to an input file destroys the original data. Therefore, command forms such as should be avoided unless the source file can be safely discarded. AUTHOR
was developed by HP. SEE ALSO
cat(1), echo(1), od(1). vis(1)
All times are GMT -4. The time now is 04:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy