|
|||||||
| 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
|
|||
|
|||
|
how to delete spaces around a word
suppose a line has one word
ex: unix how to delete space around that word? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
in vi: Code:
%s= ==g to remove all spaces, leave the g off if you only want to remove the first occurance of a space on each line. or Code:
tr -d '\040' < originalfile > outputfile |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
One way: Code:
echo ' unix ' | sed 's/^[ ]*//g;s/[ ]*$//g' |
|
#4
|
|||
|
|||
|
In oracle we have a function called trim. is there a similiar function in unix?
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
There are many ways to "skin that cat": Code:
echo ' unix ' | awk '{print$1}'
echo ' unix ' | read NEWVALUE
NEWVALUE=$(echo ' unix ') |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Quote:
Code:
#!/bin/ksh
str=' 1 2 3 5 '
function trim {
echo "${1}" | /usr/xpg4/bin/awk '{gsub("^[[:space:]]+|[[:space:]]+$", "", $0); printf("%s\n", $0)}'
}
echo "[${str}] -> [$(trim "${str}")]" |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Code:
cat file | while read s
do
echo $s
done |
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search the word to be deleted and delete lines above this word starting from P1 to P3 | vsachan | Shell Programming and Scripting | 2 | 05-24-2011 03:36 AM |
| How to remove multiple spaces in between word? (VI EDITOR)? | rabeel | Ubuntu | 1 | 03-09-2011 02:40 AM |
| Retaining Spaces within a word | RcR | UNIX for Dummies Questions & Answers | 0 | 09-09-2007 11:19 PM |
| Delete spaces in between fields | guiguy | Shell Programming and Scripting | 12 | 03-31-2006 08:38 AM |
| delete white spaces | DebianJ | Shell Programming and Scripting | 2 | 10-12-2005 01:30 PM |
|
|