The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Help needed in padding leading zeros jakSun8 Shell Programming and Scripting 12 07-02-2008 07:41 PM
Byte Padding naan High Level Programming 6 02-22-2007 05:09 AM
Padding zeros after removing commas in file pranag21 HP-UX 1 11-09-2005 10:22 PM
Padding vijaygopalsk UNIX for Dummies Questions & Answers 2 06-27-2003 10:51 AM
Padding issues informshilpa UNIX for Advanced & Expert Users 2 03-01-2002 01:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-13-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 532
If you have exactly 3 fields in the file, then:

Code:
$
$ cat file.csv
"100","100","ABC"
"100","200","ABC"
"100","300","ABC"
$
$ # awk
$ awk -F, '{gsub(/"/,""); printf("\"%s\",\"%07s\",\"%s\"\n",$1,$2,$3)}' file.csv
"100","0000100","ABC"
"100","0000200","ABC"
"100","0000300","ABC"
$
$ # or perl
$ perl -ne '{chomp; split /","/; printf("%s\",\"%07s\",\"%s\n",$_[0],$_[1],$_[2])}' file.csv
"100","0000100","ABC"
"100","0000200","ABC"
"100","0000300","ABC"
$
tyler_durden
  #2 (permalink)  
Old 05-13-2009
limshady411 limshady411 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Arizona
Posts: 10
Thanks Tyler, this does the trick!
  #3 (permalink)  
Old 05-13-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,533
if you have Python
Code:
#!/usr/bin/env python
import csv
filename = "file"
reader = csv.reader(open(filename))
writer = csv.writer( open("newfile.csv","wb"), quoting=csv.QUOTE_ALL)
for row in reader: 
    writer.writerow(row)
output
Code:
# ./test.py
# more newfile.csv
"100","0000100","ABC"
"100","0000200","ABC"
"100","0000300","ABC"

Last edited by ghostdog74; 05-18-2009 at 08:50 PM..
  #4 (permalink)  
Old 05-18-2009
limshady411 limshady411 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Arizona
Posts: 10
I don't have python, but thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0