conversion of spaces into CSV format file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting conversion of spaces into CSV format file
# 1  
Old 05-07-2011
converting spaces input file from one of the backup commands into CSV format file

INput file attached in thread : Column widths at 24,73,82,87,121 characters (sed 's/./,/24;s/./,/73;s/./,/81;s/./,/87;s/./,/121;s/ *, */,/g' fixedinputfile >output.csv
). The client wants instead of hard coding the column widths as they are not fixed .he has given the hint stating that (
----------------------- ------------------------------------------------ ------- ----- --------------------------------- ---------------------------------------- second line in Input file attached in thread)

In second line of input file .and asked to
generate variables 1 to 6 = field 1 colunm width, field 2 column width, etc then use these to divide each row of data. could any please help on this..

could someone help with shelll script code .,

Last edited by sreenath1037; 05-07-2011 at 03:11 AM..
# 2  
Old 05-07-2011
use something like this
Quote:
awk -F' ' '{len1=length($1)} END {print len1}'
# 3  
Old 05-07-2011
Is this what you are looking for?

Code:
#!/bin/bash

j=1;data=$( grep ^- fixedinputfile )
for i in $data;do
  now=$(echo $i | wc -c); ((val=val+now))
  width[$j]=$val; ((j=j+1))
done
sed "s/./,/${width[1]};s/./,/${width[2]};s/./,/${width[3]};s/./,/${width[4]};s/./,/${width[5]};s/ *, */,/g" fixedinputfile >output.csv

regards,
Ahamed
# 4  
Old 05-07-2011
Thanks buddy ., its working ...this is what i was looking for...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Conversion of Binary csv file

Hello, I have a binary csv file that was created on 'Red Hat Enterprise Linux Server release 6.6'. Now we have transferred all files on Ubuntu 16.04.2 LTS/xenial On opening the file in Ubuntu, there are special characters ... (8 Replies)
Discussion started by: nans
8 Replies

2. Shell Programming and Scripting

perl : number to date conversion in CSV file

I have a CSV file in the below format. while generating CSV file from excel sheet , date in excel sheet(Format :Mon 8/28/2012) got converted into the below format with numbers 41148,41149 so on. Could anyone please let me know how to the convert the numbers(41148,41149 so on.) to its actual... (2 Replies)
Discussion started by: giridhar276
2 Replies

3. Shell Programming and Scripting

Conversion of xhtml data into csv format using dump utility

Hi Unix Gurus, I tried to convert the attached xhtml table content into csv file using unix shell script (lynx -dump filename) and got the below results: Title ID Owner Priority Estimate Project Change Date Changed By Complexity Create Date Created By Detail Estimate Total De tail... (6 Replies)
Discussion started by: bi.infa
6 Replies

4. Shell Programming and Scripting

Conversion of spaces Text file into CSV format file

Input file (each line is separaed by spaces )given below: Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- -----... (18 Replies)
Discussion started by: sreenath1037
18 Replies

5. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

6. Ubuntu

Conversion of the format of a file in linux

How to convert a rtf file to a ttf file in ubuntu terminal? (2 Replies)
Discussion started by: poonam.gaigole
2 Replies

7. Shell Programming and Scripting

Flat file to csv conversion

Hi Guy's can someone help me in converting the following I have a flat text file which has several thousand lines which I need to convert to a csv it's got a consistent format but basically want every time it hit's txt to create a new line with the subsequent lines comma delimited for example ... (6 Replies)
Discussion started by: p1_ben
6 Replies

8. Shell Programming and Scripting

Conversion of .xls file to .csv file

Hi Folks, I've to convert manually couple of *.xls files to *.csv files everyday :( so i was just wondering if anyone could just help me with a shell script or awk script to automate the process :) PS : Problem is that i cannot use any third party software for the conversion. Thanking... (1 Reply)
Discussion started by: chaturvedi
1 Replies

9. Shell Programming and Scripting

DateTime Format Conversion in a File

Hi Pals. I have a file which is in the below format. 2007/10/15-12:04:24,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User1' 2007/10/15-12:04:26,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User2' 2007/10/15-12:04:29,'CRLift','TH-42PX75U','BestBuy','W01P0207',22,15,'User3'... (4 Replies)
Discussion started by: srikanthgr1
4 Replies

10. UNIX for Advanced & Expert Users

Flat File Conversion Format

Hi all, I've a flat file in this format: = " Record 1 Field1 -> XXXX Field2 -> 9558 Field3 -> 55AA Record 2 Field1 -> YYYY Field2 -> 12345 Field3 -> aa23 " And i want to convert it to (4 Replies)
Discussion started by: Loobian
4 Replies
Login or Register to Ask a Question