|
|||||||
| 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
|
|||
|
|||
|
Need help removing leading spaces from one field in comma seperated file
Using awk or sed, I'd like to remove leading spaces after a comma and before a right justified number in field 6. Sounds simple but I can't find a solution. Each field's formatting must stay intact. Input: Code:
40,123456-02,160,05/24/2012,02/13/1977, 10699.15,0 Output: Code:
40,123456-02,160,05/24/2012,02/13/1977,10699.15,0 Any help is appreciated! ~Scottie Last edited by joeyg; 06-13-2012 at 01:13 PM.. Reason: Please wrap data and sripts with CodeTags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Your example only showed this occurring once; not sure if it occurs outside of that 6th column. But... Code:
echo 40,123456-02,160,05/24/2012,02/13/1977, 10699.15,0 | sed 's/, /,/' 40,123456-02,160,05/24/2012,02/13/1977,10699.15,0 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
My apologies. My original post was not very clear. I don't have any code yet for awk or sed, just a file with multiple lines of data that look like the example below (this is better than my original example): Code:
1, 3456-78, 42,05/02/2012,05/12/1984, 1230.00, 4 What I'd like to do is remove leading spaces from every field, if any, while retaining the existing formatting of each field's number. So after some scripting magic the above line should look like: Code:
1,3456-78,42,05/02/2012,05/12/1984,1230.00,4 Thanks a bunch for your help! |
|
#4
|
|||
|
|||
|
Hi Scottie1954, Try the following, there are two spaces before the star; Code:
cat "filename" | sed 's/, */,/g' > "newfilename" Regards Dave |
| The Following User Says Thank You to gull04 For This Useful Post: | ||
Scottie1954 (06-15-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
That got me going the right direction, so thank you. It took me two steps to get what I wanted: Code:
sed 's/, */,/g' FILE1 >junk1 # remove leading spaces before commas Code:
sed 's/^ *//' junk1 >junk2 # remove leading space(s) from beginning of line There's probably a more efficent way to combine the two but this got the job done. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Hi Scottie1954, Sorry I didn't look at the post properly, it would have worked with; Code:
cat "filename" | sed 's/ */,/g' > "newfilename" Where the command is the same as before, just minus the comma "," Regards Dave |
| 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 |
| Convert comma seperated file to line seperated. | pinnacle | Shell Programming and Scripting | 6 | 12-07-2010 07:45 PM |
| Removing leading spaces from the variable value. | khedu | Shell Programming and Scripting | 3 | 09-28-2009 03:26 PM |
| removing special characters, white spaces from a field in a file | priyanka3006 | Solaris | 2 | 08-04-2009 09:30 AM |
| Removing blank lines from comma seperated and space seperated file. | pinnacle | Shell Programming and Scripting | 11 | 05-08-2009 11:58 AM |
| Removing leading and trailing spaces only in PERL | kumar04 | Shell Programming and Scripting | 2 | 04-04-2009 03:17 PM |
|
|