|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Are you using a GNU sed? Then you can do this:
find . -type f -exec sed -i 's/Info\*/Info\&/g' {} \; HTH, -- Stephan Grein, <stephan at stephan minus rockt dot de> https://stephan-rockt.de GnuPG-Key-ID: 0xF8C275D4 FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Hi I need to replace all the occurrences of Info* with the string Info& in all the files in a given directory. the command below which was thankfully supplied by some one here did not do it. I tried to escape the "*" character but could not. for file in *; do [ -f "$file" ] || continue; sed 's/Info*/Info&/g' "$file" > tempfile && cp -- tempfile "$file"; done who can I do it? thanks |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Gary Wessle <phddas@yahoo.com> wrote:
> > Hi > I need to replace all the occurrences of > Info* > with the string > Info& > in all the files in a given directory. > > the command below which was thankfully supplied by some one here did > not do it. I tried to escape the "*" character but could not. > > for file in *; do [ -f "$file" ] || continue; sed > 's/Info*/Info&/g' "$file" > tempfile && cp -- tempfile "$file"; done You need to escape both, the asterisk and the ampersand in sed's substitute command: for file in *; do [ -f "$file" ] || continue sed 's/Info\*/Info\&/g' "$file" >tempfile \ && cp -- tempfile "$file" done -- Kenan Kalajdzic |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2006-12-09, 00:50(+11), Gary Wessle:
> > Hi > I need to replace all the occurrences of > Info* > with the string > Info& > in all the files in a given directory. > > the command below which was thankfully supplied by some one here did > not do it. I tried to escape the "*" character but could not. > > for file in *; do [ -f "$file" ] || continue; sed > 's/Info*/Info&/g' "$file" > tempfile && cp -- tempfile "$file"; done [...] Unluckily enough, the "*" happens to be special in the LHS (left hand side) of a sed substitution (where it means 0 or more of the preceding item) and "&" on the RHS (where it is replaced by the matched portion). So, that command replaces Inf with InfoInf and Infooo with InfoInfooo for instance. for file in *; do [ -f "$file" ] && sed 's/Info\*/Info\&/g' < "$file" > tempfile && cp -- tempfile "$file" done (note that the "--" in the cp command line is only necessary for the GNU version of cp, other implementations don't allow options after arguments). -- Stéphane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Gary Wessle wrote:
> I need to replace all the occurrences of > Info* > with the string > Info& > in all the files in a given directory. find . -type f -exec sh -c '<<\! ed -- {} 1,$s/Info\*/Info\&/g w q' \; |
|
![]() |
| Outils de la discussion | |
|
|