![]() |
|
|
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 |
| update file contents using shell script | drams | Shell Programming and Scripting | 5 | 10-09-2008 04:56 PM |
| Unix shell script to parse the contents of comma-separated file | KrishnaSaran | Shell Programming and Scripting | 11 | 06-20-2008 06:43 AM |
| Converting Shell Script to HTML | davwel | Shell Programming and Scripting | 3 | 10-25-2007 11:25 PM |
| search for the contents in many file and print that file using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-07-2007 11:17 PM |
| converting contents of a character array to int | jyotipg | High Level Programming | 5 | 07-19-2006 10:18 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Shell script for converting file contents into CSV
Hi, I am new in unix, I just want to replace some values from text file according to column numbers. Like, I am having a table as given below: Code:
val1 val2 val3 val4 val5 val6 val7 val8 val9 val10 val11 val12 val13 Now i want to replcae the blank value for a column with 'null' and then converted it into comma separated value(csv) as: Code:
val1,val2,val3,val4,val5 val6,val7,val8,null,val9 val10,val11,null,val12,val13 how do i do this? Please suggest Last edited by Ygor; 02-06-2009 at 02:19 AM.. Reason: Added CODE tags for readability. |
|
|||||
|
You can use sed or tr. The ff. links may prove to be useful:
how to remove spaces in a string using sed. sed : remove whitespace replace space or spaces in a line of a file with a single : |
|
||||
|
Thanx for quick reply, but it doesn't work for me.
I rephrase my problem: Every row in a file should have 5 seperate columns in which values are tab seperated. and there are some blank values, say column 4 of row 2 is blank and column 3 of row 3 is blank. I need to first fill this blank value with 'null' and then convert it into CSV i.e the script should consider the tab value as blank and replace it with ',' but should not consider the blank value of a column as blank space. sed will replace tabs and blank values of a column with ',' so the output becomes row 1 has all 5 values seperated with comma row 2 has first 3 values seperated with comma and then sed consider the tab space and blank value as blankspace and replace it with comma and then write the 5th column value so the output becomes val1,val2,val3,val5. It should be like val1,val2,val3,null,val5 |
![]() |
| Bookmarks |
| Tags |
| file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|