If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > sed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-18-04, 08:50
Daryl Lim Daryl Lim is offline
Registered User
 
Join Date: May 2004
Posts: 11
sed

Hi

does anyone know what does the sed command do:

sed "s/[A-Z]/&/g" file

i tried running but there is no effect on the uppercase letters in the file. Is the amperstand a metacharacter in sed?
Reply With Quote
  #2 (permalink)  
Old 06-18-04, 09:19
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
This isn't going to do anything that you would notice!

'&' in a substitution represents the pattern that was matched, so you are replacing your character A-Z, with that same character.

Try...

sed "s/[A-Z]/&&/g" file

...and you will see each character repeated because you are replacing the matched pattern with 'twice' the matched pattern.
Reply With Quote
  #3 (permalink)  
Old 06-18-04, 09:19
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
Originally Posted by Daryl Lim
Hi

does anyone know what does the sed command do:

sed "s/[A-Z]/&/g" file

i tried running but there is no effect on the uppercase letters in the file. Is the amperstand a metacharacter in sed?
this sed does not change anything.
'&' back-references the matched string.

doing 'man sed' yields:
Quote:
An ampersand (&) appearing in the replacement
will be replaced by the string matching the
RE. The special meaning of & in this context
can be suppressed by preceding it by
backslash. The characters \n, where n is a
digit, will be replaced by the text matched by
the corresponding backreference expression.
For each backslash (\) encountered in scanning
replacement from beginning to end, the follow-
ing character loses its special meaning (if
any). It is unspecified what special meaning
is given to any character other than &, \ or
digits.
Reply With Quote
  #4 (permalink)  
Old 06-18-04, 21:48
Daryl Lim Daryl Lim is offline
Registered User
 
Join Date: May 2004
Posts: 11
sed

what about this command below:

sed "10r text" file

thanks
daryl
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On