![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| How to remove trailing spaces | mahek_bedi | UNIX for Dummies Questions & Answers | 2 | 08-10-2007 07:21 AM |
| Removing leading and trailing spaces of data between the tags in xml. | jhmr7 | UNIX for Dummies Questions & Answers | 2 | 05-18-2005 10:27 AM |
| Strip leading and trailing spaces only in a shell variable with embedded spaces | jerardfjay | Shell Programming and Scripting | 6 | 03-07-2005 02:24 PM |
| Leading and Trailing Spaces | sleepster | Shell Programming and Scripting | 7 | 10-29-2003 11:48 PM |
| removing trailing spaces of a particular column in a file | rooh | UNIX for Dummies Questions & Answers | 2 | 01-12-2002 11:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Removing trailing spaces from delimited files
Hi All
I have a file of the following format (delimited by |) this is field 1 | field 2 (lots of blank spaces) | field 3 (lots of blank space) | field 1 | more text (lots of blank spaces) | dhjdsk | Is there a way I can remove trailing spaces between the end of the text in each field and the delimiter? E.g. I would like to end up with the following... this is field 1 | field 2 | field 3 | field 1 | more text | dhjdsk | Is this possible? |
|
||||
|
Quote:
Quote:
Code:
echo "a | b | c |" | sed "s/[' ']*|/|/g" |
|
||||
|
sed -e "s/[' ']*|/|/g" $FILE
Using the line of code above, i get trailing spaces to be removed between the end of the field and the delimiter. I was hoping someone might explain how the command knows to take from the last space. For example, if i have a field a row in $FILE such as... this is field 1 | this is field 2 | a lot of text in field 3 ...how does the command know to remove the space after the "1" instead of taking everything after the first space, i.e., after "this". Any explanation would be hugely appreciated. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|