regex question

Hi

I have a question on regex

There is a line in a script like
my_file="$(echo SunMonTueWed | sed "s/[A-Z]/_&g") "

My question what does the expression _&g do.

Obviously in this example the output is
_Sun_Mon_Tue_Wed

Another question can i use some trick to get the result like
Sun_Mon_Tue_Wed instead of _Sun_Mon_Tue_Wed

regards
Hrishy

There is a typo in that string

my_file="$(echo SunMonTueWed | sed "s/[A-Z]/_&g") "

should read as

my_file=$(echo SunMonTueWed | sed "s/[A-Z]/_&/g")

In the sed world, & stands for whatever pattern the regex matches. In your case, it could be one of the upper case alphabets.

To get your desired result you could use

echo "SunMonTueWed" | sed -e "s/[A-Z]/_&/g;s/^_//"

Hi Vino

Thanks for correcting my post and also for a fast reply.

regards
Hrishy

Hi vino,

I have a file cpu with its content as follows:

Data Collected: 05/17/08 17:19:49

Refresh Interval: 600 seconds

GlancePlus Started/Reset: 05/17/08 08:19:45
B3692A GlancePlus C.03.72.00 17:29:49 UXAMSK01 9000/800 Current Avg High
-------------------------------------------------------------------------------
CPU Util SSUUUUU | 16% 9% 22%
Disk Util F | 1% 5% 12%
Mem Util SSSSSSSSSSUUUUUUUUBBBBB | 46% 45% 46%
Swap Util UUUURRRRR | 17% 16% 17%
-------------------------------------------------------------------------------
IO BY FILE SYSTEM Users= 8
Idx File System Device Type Logl IO Phys IO
--------------------------------------------------------------------------------
1 / /dev/vg00/lvol3 vxfs 24.8/ 25.1 0.5/ 0.5
2 /stand /dev/vg00/lvol1 hfs 0.0/ 0.0 0.0/ 0.0
3 /var /dev/vg00/lvol8 vxfs 0.2/ 0.3 1.9/ 2.1
4 /usr /dev/vg00/lvol7 vxfs 35.2/ 17.7 0.9/ 0.7

Top disk user: PID 11053, s_server 10.0 IOs/sec S - Select a Disk

Now i m using this code

sed -n '1p;8,10 {;s/^\([^ ]\) [^0-9]*\([0-9]*%\).$/\1 \2/p;}' cpu

to get output as:

Data Collected: 05/17/08 17:19:49
CPU 16%
Disk 1%
Mem 46%

But i dont know how this code works exactly
could u please help me explain this code in detail

Its a bit urgent

Thanks