Sponsored Content
Top Forums Shell Programming and Scripting Converting csv file to flat file Post 303023609 by Don Cragun on Thursday 20th of September 2018 12:27:53 AM
Old 09-20-2018
Given that the sample output you provided is not formatted at all like you said you wanted and, instead, just changes the <comma>s in your CSV file to <space>s; I don't know whether you want the input data to be left-justified in the output or right-justified.

Assuming that you want left-justified text in your twenty character and ten character output fields, two (of many) simple ways to do what you want include an awk script:
Code:
awk -F, '{printf("%-20.20s%-10.10s\n",$1,$2)}' file.csv

and a shell while read loop:
Code:
while IFS=, read c i
do	printf '%-20.20s%-10.10s\n' "$c" "$i"
done < file.csv

if you want right-justified text instead of left-justified text, remove both of the minus signs from the printf format strings in either of the above scripts.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting Pivot file to flat file

I have a file in this format. P1 P2 P3......................... A001 v11 v21 v31...................... A002 v12 v22 v32............................ A003 v13 v23 v33.......................... A004 v14 v24 v34.............................. . . . A00n... (2 Replies)
Discussion started by: vskr72
2 Replies

2. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies

3. Shell Programming and Scripting

Converting Column to Rows in a Flat file

Hi, Request To guide me in writing a shell program for the following requirement: Example:if the Input File contains the follwing data Input File Data: 80723240029,12,323,443,88,98,7,98,67,87 80723240030,12,56,6,,,3,12,56,6,7,2,3,12,56,6,7,2,3,88,98,7,98,67,87... (5 Replies)
Discussion started by: srinikal
5 Replies

4. UNIX for Advanced & Expert Users

Problem in converting password protected excel file to csv file in unix

I need to convert a password protected excel file which will be in UNIX server to a comma separated file. For this I need to open the excel file in UNIX box but the UNIX box doesn't prompt for password instead it is opened in an encrypted manner. I could manually ftp the excel file to local... (2 Replies)
Discussion started by: Devivish
2 Replies

5. UNIX for Advanced & Expert Users

Converting .csv file into .xls file and send it to inbox

Hi All, I wrote a script to extract data from Oracle DB and place it in a text file , and I have coverted .txt file into comma seperated .csv file and I sent it to my mail box . I can get .xls file in my inbox.I am getting all data in same column and in different rows , without column... (1 Reply)
Discussion started by: krthkmuthu
1 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. Shell Programming and Scripting

Converting a flat file in XML

Hello Friends, I am new to UNIX shell scripting. Using bash....Could you please help me in converting a flat file into an XML style output file. Flat file: (Input File entries looks like this) John Miller: 617-569-7996:15 Bunting lane, staten Island, NY: 10/21/79: 60600 The... (4 Replies)
Discussion started by: humkhn
4 Replies

8. UNIX for Advanced & Expert Users

Converting the date format in a flat file

Hi All, I am new to this forum, could any one help me out in resolving the below issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1... (0 Replies)
Discussion started by: av_sagar
0 Replies

9. Shell Programming and Scripting

Help with converting XML to Flat file

Hi Friends, I want to convert a XML file to flat file. Sample I/p: <?xml version='1.0' encoding='UTF-8' ?> <DataFile xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' contactCount='4999' date='2012-04-14' time='22:00:14' xsi:noNamespaceSchemaLocation='gen .xsd'> <Contact... (3 Replies)
Discussion started by: karumudi7
3 Replies

10. Shell Programming and Scripting

reading a csv file and creating a flat file

hi i have written a script for reading a csv file and creating a flat file, suggest if this script can be optimized #---------------- FILENAME="$1" SCRIPT=$(basename $0) #-----------------------------------------// function usage { echo "\nUSAGE: $THIS_SCRIPT file_to_process\n"... (3 Replies)
Discussion started by: mprakasheee
3 Replies
bidiv(1)							       Ivrix								  bidiv(1)

NAME
bidiv - bidirectional text filter SYNOPSIS
bidiv [ -plj ] [ -w width ] [file...] DESCRIPTION
bidiv is a filter, or viewer, for birectional text stored in logical-order. It converts such text into visual-order text which can be viewed on terminals that do not handle bidirectionality. The output visual-order text is formatted assuming a fixed number of characters per line (automatically determined or given with the -w parameter). bidiv is oriented towards Hebrew, and assumes the input to be a Hebrew and ASCII text encoded in one of the two common logical-order encod- ings: ISO-8859-8-i or UTF-8. Actually, bidiv guesses the encoding of its input at a character by character basis, so the input might be a mix of ISO-8859-8-i and Hebrew UTF-8. bidiv's output is visual-order text, in either the ISO-8859-8 or UTF-8 encoding, depending on your locale setting. bidiv reads each file in sequence, converts it into visual order and writes it on the standard output. Thus: $ bidiv file prints file on your terminal (assuming it has the appropriate fonts, but no bidirectionality support), and: $ bidiv file1 file2 | less concatenates file1 and file2, and shows the results using the pager less. If no input file is given, bidiv reads from the standard input file. For more ideas on how to use bidiv, see the EXAMPLES section below. OPTIONS
-p Paragraph-based direction (default): When formatting a bidirectional output line, bidiv needs to be aware of that line's base direc- tion. A line whose base direction is RTL (right to left) gets right-justified and its first element appears on the right. Otherwise, the line is left-justified and its first element appears on the left. The -p option tells bidiv to choose a base direction per paragraph, where a paragraph is delimited by an empty line. This is bidiv's default behavior, and usually gives the expected results on most texts and emails. The direction of the entire paragraph is chosen according to the first strongly-directioned character (i.e., an alphabetic charac- ter) appearing in the paragraph. Currently, if the first output line of a paragraph has no directional characters (e.g., a line of minus signs before an email signature, or a line containing only numbers) that line is output with the same direction of the previ- ous paragraph, but it does not determine the direction of the rest of the paragraph. If the first line of the first paragraph does not have a direction, the RTL direction is arbitrarily chosen. -l Line-based direction: This option choose an alternative method of choosing each output line's base direction. When this option is enabled, the base direction of each output line is determined on its own (again, according to the first character on the line with a strong direction). This method may give wrong results in the case where a line starts with a word of the opposite direction. This case is rare, but does happen under random line-splitting circumstances, or when the text is defining words of a foreign language. -j Do not justify: By default, RTL lines are right-justified, i.e., they are padded with spaces on the left when shorter than the required line width (see the -w option). The -j option tells bidiv not to preform this justifications, and leave short lines unpadded. -w width bidiv formats its output for lines of the given width. Lines are split when longer than this width, and RTL lines are right-justfied to fill that width unless the -j option is given. When the -w option is not given, bidiv uses the value of the COLUMNS variable, which is usually automatically defined by the user's shell. When that both the -w option and the COLUMNS variable are missing, the default of 80 columns is used. OPERANDS
The following operand is supported: file A path name of an input file. If no file is specified, the standard input is used. EXAMPLES
1. bidiv README | less 2. man something | bidiv | less (or groff -man -Tlatin1 something.1 |sed 's/.^H(.)/1/g' |../bidiv -w 65) 3. set "bidiv" as a filter for your mail program (mutt, pine, etc.) for viewing mail with the ISO 8859-8-i character set, and Hebrew UTF-8 mail. ENVIRONMENT
COLUMNS see -w option. EXIT STATUS
The following exit values are returned: 0 All input files were output successfully. >0 An error occurred. AUTHOR
Written by Nadav Har'El, http://nadav.harel.org.il. Please send bug reports and comments to nyh@math.technion.ac.il. The latest version of this software can be found in ftp://ftp.ivrix.org.il/pub/ivrix/src/cmdline SEE ALSO
cat(1), fribidi(3) Bidiv 7 Jan 2006 bidiv(1)
All times are GMT -4. The time now is 08:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy