|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
insert comma
my file looks like this:
297 PC Closed 07/10/12 999000098 AMERICAN SOCIETY FOR HEALTHCAR 0.00 USD 1 NAI i want to look line this: 297,PC,Closed,07/10/12,999000098,AMERICAN SOCIETY FOR HEALTHCAR,0.00,USD,1,NAI |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try this:
cat "File Name" | sed -e 's/ /,/g' |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
that's useless use of cat With your command it replaces all the spaces with ",". which is not desired output. see the output below.. Code:
$ echo "297 PC Closed 07/10/12 999000098 AMERICAN SOCIETY FOR HEALTHCAR 0.00 USD 1 NAI" | sed -e 's/ /,/g' 297,PC,Closed,07/10/12,999000098,AMERICAN,SOCIETY,FOR,HEALTHCAR,0.00,USD,1,NAI Hi lawsongeek, Could you provide some more lines from your input. Is Columns are tab separated? |
|
#4
|
|||
|
|||
|
5016487 RS Issued 08/22/12 7621 MOLECULAR DEVICES INC 4500.00 USD 1 NAI
5016488 RS Issued 08/23/12 7621 MOLECULAR DEVICES INC 2000.00 USD 1 NAI 5016490 RS Issued 09/04/12 22050 WUXI APPTEC, INC 3700.00 USD 1 NAI |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Try something this.... ![]() Code:
awk '{for (i=6;i<=(NF-4);i++){if(p){p=p" "$i}else{p=$i}}{print $1,$2,$3,$4,$5,p,$(NF-3),$(NF-2),$(NF-1),$NF;p=""}}' OFS=\, file |
| 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 |
| Insert comma in place of column | manigrover | Shell Programming and Scripting | 5 | 08-13-2012 02:29 AM |
| Script using Sed :Search all patterns & after the last Patter, insert a newLine with Comma Sep Value | evrurs | Shell Programming and Scripting | 8 | 08-01-2012 12:49 PM |
| Need to remove comma from description in Comma separated csv file | ops_team | Shell Programming and Scripting | 11 | 03-22-2012 06:40 AM |
| insert comma in a text file | GoldenFire | UNIX for Dummies Questions & Answers | 7 | 12-15-2010 11:21 AM |
| Insert comma based on max number of column | nicholas_ejn | Shell Programming and Scripting | 8 | 12-11-2008 01:08 PM |
|
|