Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace all tabs, multiple tabs and multiple spaces, white spaces with single space 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
hi,
the input file text contains multiple spaces, tabs, multible tabs and I need to replace all of them with single space

which command removes all leading and trailins spaces:

sed "s/^[[:space:]]*//;s/[[:space:]]*$//"

I tried to use this for removign white spaces inside the it doesn't do it.. (the red commands)

Code:
# echo "  \t     sdfsd s            sdfs        sdfs            ete\t"
             sdfsd s            sdfs        sdfs            ete
# echo "  \t     sdfsd s            sdfs        sdfs            ete\t"|sed "s/^[[:space:]]*//;s/[[:space:]]*$//"
sdfsd s            sdfs        sdfs            ete
# echo "  \t     sdfsd s            sdfs        sdfs            ete\t"|sed "s/^[[:space:]]*//;s/[[:space:]]*$//"|sed s/$/\|/
sdfsd s            sdfs        sdfs            ete|
# echo "  \t     sdfsd s            sdfs        sdfs            ete\t"|sed "s/^[[:space:]]*//;s/[[:space:]]*$//"|[red]sed "s/[[:space:]]*/\ /"[/red]
 sdfsd s            sdfs        sdfs            ete
# echo "  \t     sdfsd s            sdfs        sdfs            ete\t"|sed "s/^[[:space:]]*//;s/[[:space:]]*$//"|[red]sed "s/[[:space:]]*/\ /g"[/red]
 s d f s d s s d f s s d f s e t e
#

what the last sed on pipe should be?
 
sed "s/^[[:space:]]*//;s/[[:space:]]*$//"|sed "s/[[:space:]][[:space:]]*/\ /g"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hello

how could I get the same in awk?

something easier from? :

awk '{ for (f=1; f <= NF; f++) { printf("%s ", $f);} print("");}'
 
awk '{gsub(/[ \t]+/," ");print}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top