![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting .ps file to .pdf file from where it is broken | sunitachoudhury | UNIX for Advanced & Expert Users | 5 | 04-07-2008 11:13 AM |
| Converting a Delimited File to Fixed width file | raghavan.aero | Shell Programming and Scripting | 2 | 06-06-2007 02:44 PM |
| Converting Pivot file to flat file | vskr72 | Shell Programming and Scripting | 2 | 10-18-2005 04:41 PM |
| Converting Text File into XML using Unix Shell Scripts | Laud12345 | Shell Programming and Scripting | 10 | 02-16-2005 01:35 PM |
| Converting a .job file | Juliette | Windows & DOS: Issues & Discussions | 6 | 12-04-2004 02:42 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Converting a text file to a csv file
I have a text file that is the output of a Netbackup report. The file it generates is just a plain text file with only white space between fields. For example:
Date Policy Type Kilobytes Retention 12/5/2005 WinNT Full 18329948 6 Months I need to write a script that will make it look like this: Date,Policy,Type,Kilobytes,Retention 12/5/2005,WinNT,Full,18329948,6 Months As you can see in the first example, the number of spaces between words aren't uniform, which complicates things a bit. If anyone has any suggestions, I would appreciate it. |
|
||||
|
This:
Code:
awk '{
for(i=1;i<5;i++)
{ printf("%s,", $i); }
for(i=5;i<=NF;i++)
{printf("%s ",$i); }
printf("\n");
}' filename
Code:
Date Policy Type Kilobytes Retention 12/5/2005 WinNT Full 18329948 6 Months 12/5/2005 WinNT Half 100 6 Months 12/5/2005 WinNT Full 200 6 Months Code:
kcsdev:/home/jmcnama> t.awk Date,Policy,Type,Kilobytes,Retention 12/5/2005,WinNT,Full,18329948,6 Months 12/5/2005,WinNT,Half,100,6 Months 12/5/2005,WinNT,Full,200,6 Months |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|