![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing blank lines from comma seperated and space seperated file. | pinnacle | Shell Programming and Scripting | 11 | 05-08-2009 12:58 PM |
| Search and then concat 4m other file (comma seperated) | szchmaltz | UNIX for Dummies Questions & Answers | 1 | 06-30-2008 03:45 AM |
| Handling .CSV( Comma seperated value) in awk | Laud12345 | Shell Programming and Scripting | 1 | 05-09-2005 05:41 PM |
| How to load comma seperated values file (*.csv) into Oracle table | handynas | UNIX for Advanced & Expert Users | 4 | 06-24-2002 01:35 PM |
| How to load comma seperated values file (*.csv) into Oracle table | handynas | UNIX for Dummies Questions & Answers | 5 | 06-05-2002 12:10 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Trimming fields for comma or pipe seperated file
I have file like this
FileA: abc , "helloworld" , america def,asia, japan ghi, africa, ipl Output Needed: abc,"helloworld",america def,asia,japan ghi,africa,ipl I would like to implement using awk. I want to trim each field for its leading and trailing spaces. |
|
||||
|
Quote:
The above script just removes spaces from any where in the line. I like to trim each field in a comma seperated file. I wrote the following code: Code:
awk '{gsub("^[ ]*","",$1);gsub("^[ ]*","",$2) ;gsub("^[ ]*","",$3) print $1,$2,$3;}' filename > filename1
awk '{gsub("[ ]*$","",$1);gsub("[ ]*$","",$2) ;gsub("^[ ]*$","",$3) print $1,$2,$3;}'filename1 > filename
Appreciate help on making this versatile |
|
||||
|
Quote:
Thankyou Franklin52 This was what i was looking for that does triming and not with in double quotes. Thanks again |
|
||||
|
Quote:
Code:
nawk -F"\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("^[ ]*","",$i);gsub("[ ]*$","",$i)}}1' OFS="\"" filetst1
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|