|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Converting txt file in csv
HI All, I have a text file memory.txt which has following values. Code:
Average: 822387 7346605 89.93 288845 4176593 2044589 51883 2.47 7600 i want to convert this file in csv format and i am using following command to do it. Code:
sed s/_/\./g < memory.txt | awk -F. '{ print $1","$2","$3","$4}' > test.csvbut I am getting output in just 3 columns. I want every value to be printed in new column. I have also used this one but result is not accurate. Code:
awk -F_ '{ print $1","$2","$3}' < memory.txt > MemoryTemp.csvplz tell me where i am doing wrong. i got this code from google. Thanks in advance. Last edited by zaxxon; 07-30-2010 at 04:35 AM.. Reason: added 1 more pair of missing code tags |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Since the 1st awk code just handles only first 3 fields you only get first 3 fields. There is also a substitution of underscores where there aren't any. So a following underscore as field separator is not working either. This code does not fit to your question at all. You can try this one - I've chosen the semicolon as separator: Code:
$> sed 's/[[:space:]]\+/;/g' memory.txt > memory.csv $> cat memory.csv Average:;822387;7346605;89.93;288845;4176593;2044589;51883;2.47;7600 |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Hi, Try this, Code:
tr -s ' ' ',' < inputfile |
|
#4
|
|||
|
|||
|
Hi, zaxxon: by choosing , (comma) as a separator, i got the required results. so thanks for your input. Code:
sed 's/[[:space:]]\+/,/g' memory.txt > memory.csv pravin27: your code is also working so thanks for your efforts. Regards, Kashif. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| converting fixed length file to delimited file | Nishithinfy | Shell Programming and Scripting | 2 | 07-02-2009 07:50 AM |
| Problem in converting password protected excel file to csv file in unix | Devivish | UNIX for Advanced & Expert Users | 2 | 03-30-2009 07:56 PM |
| Converting a Delimited File to Fixed width file | raghavan.aero | Shell Programming and Scripting | 2 | 06-06-2007 02:44 PM |
| Converting ps file to pdf | jasjot31 | Shell Programming and Scripting | 3 | 09-27-2006 06:09 AM |
|
|