|
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
|
|||
|
|||
|
Replace spaces at a specific Location
Hello All, I have a comma separated file which needs to be loaded to the database. But, I need to trim the white spaces for a specific column before its loaded. Below is the sample line from the input file: Code:
690,690,0575,"01011940","01011940", , , , , ,36720,36722,V2020,V2999, 690,690,0576,"01011940","01011940", , , , , ,3674 ,3674 ,V2020,V2999, 690,690,0577,"01011940","01011940", , , , , ,36860,36860,V2020,V2999, 690,690,0578,"01011940","01011940", , , , , ,36869,36869,V2020,V2999, 690,690,0579,"01011940","01011940", , , , , ,3688 ,3688 ,V2020,V2999, The text in bold needs to be trimmed if there are any spaces before and after the data. To be specific any spaces between the 11th and 12th column should be removed and rest of them should be maintained. Is there any specific command that can do this for me? Thanks for you help in advance. Last edited by Franklin52; 02-10-2012 at 03:07 AM.. Reason: Please use code tags for code and data samples, thank you |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
perl -F, -ane '$F[-4]=~s/ $//;print join(",", @F)' inputfile |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
try this Code:
awk -F"," '{$1=$1;print}' filename |
|
#4
|
|||
|
|||
|
Code:
tr -d ' ' < file |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
@parthmittal2007: Wouldn't that delete spaces in other fields too? Requirement is to delete spaces only from those fields marked in bold.
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Just column 12 or both column 11 and 12? Code:
awk -F, '{gsub(/[ \t]/,x,$11);gsub(/[ \t]/,x,$12)}1' OFS=, infile |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Praveenkulkarni (02-10-2012) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thank you very much. This does it exactly what I needed.. Need to learn awk for sure.. Very helpful. Thanks again
|
| 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 |
| Help with replace character based on specific location | perl_beginner | Shell Programming and Scripting | 6 | 03-18-2011 03:57 AM |
| Find and replace a string a specific value in specific location in AIX | techmoris | Shell Programming and Scripting | 5 | 03-11-2010 06:24 PM |
| Updating the files at specific location | swapnil.nawale | Shell Programming and Scripting | 2 | 12-29-2009 01:19 PM |
| how to Add word at specific location in line | crackthehit007 | Shell Programming and Scripting | 10 | 09-09-2009 07:44 AM |
| using sed to replace a specific string on a specific line number using variables | todd.cutting | Shell Programming and Scripting | 2 | 08-13-2009 09:40 PM |
|
|