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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with tabulator regexp in sed on AIX 2

Status
Not open for further replies.

zaxxon

MIS
Dec 12, 2001
226
DE
Hi,

I want to match tabulators with sed on an AIX 5.3 box. I tried it with following:

Code:
echo "              "| sed 's/^[ \t]*//g'
      ^^^^^^^^^^^^^^
      Contains some spaces and a tab.

On my Linux box it works fine, on my AIX 5.3 box it doesn't catch/match the tab.
I tried it with a text file and checked with vi setting ":set list" to show the tabs and same problem occurs.
Anyone got an idea?

laters
zaxxon
 
t=`echo "\t"`
echo " " | sed "s!^[ $t]*!!g"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Works, thank you and a star :) Can you explain why this happens? I don't understand why it doesn't work like on my linux box. Just because of a different "sed"-Version like there is with awk, nawk, gawk and so on?

laters
zaxxon
 
I think a linux box use the GNU version of sed.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
On my AIX 5.1 system putting an actual space and an actual tab in between the square brackets works. It's a bit difficult to read (I mean, in six months time, when you review the code, can you see what's there?) but, on my test system
Code:
#echo "b<tab>a" | sed 's/[<space><tab>]//g'
ba

Ceci n'est pas une signature
Columb Healy
 
Even better, and it works on my AIX, is to use
Code:
echo "a<tab><space>b" | sed 's/[[:space:]]//g'
The [[:space:]] matches all forms of white space. From the IBM web site
You can also use the [:charclass:] notation to match file names within a range indication. This format instructs the system to match any single character belonging to class. The definition of which characters constitute a specific character class is present through the LC_CTYPE category of the setlocale subroutine. All character classes specified in the current locale are recognized.

The names of some of the character classes are:

* alnum
* alpha
* cntrl
* digit
* graph
* lower
* print
* punct
* space
* upper
* xdigit.

For example, [[:upper:]] matches any uppercase letter.

Ceci n'est pas une signature
Columb Healy
 
I remember them from O'Reilly's awk & sed pocket reference too but I have never used them. Works excellent, tyvm.

laters
zaxxon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top