|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi
when writing a sed command as sed 's/../../..' filename it takes input as some file, can a string be given as input as sed 's/../../..' string thanx |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
JyotiC wrote: > hi > when writing a sed command as > sed 's/../../..' filename > it takes input as some file, > can a string be given as input as > sed 's/../../..' string > sed -e 's/.../.../..' << [EOF] string [EOF] provided the string doesnot contain [EOF] in it. but you can override this by storing the string in a variable. or we can pipe it: var='string' printf '%s\n' "$var" | sed -e 's/../../..' |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 21 Aug 2006 02:43:37 -0700, JyotiC wrote:
> when writing a sed command as > sed 's/../../..' filename > it takes input as some file, > can a string be given as input as > sed 's/../../..' string [...] string='whatever other line in $string' printf '%s\n' "$string" | sed 's/.../.../' But beware that sed will perform substitutions for every line in $string one after the others (not on the whole $string at once). Note that expr can be used instead of sed to extract things from a string. See also: awk ' BEGIN { sub(/foo/, "bar", ARGV[1]) print ARGV[1] exit(0) }' "$string" -- Stephane |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 21 Aug 2006 03:24:43 -0700, Rakesh Sharma wrote:
> > JyotiC wrote: >> hi >> when writing a sed command as >> sed 's/../../..' filename >> it takes input as some file, >> can a string be given as input as >> sed 's/../../..' string >> > > sed -e 's/.../.../..' << [EOF] > string > [EOF] [...] I wouldn't use wildcards in the herefile terminator, that's asking for trouble. debian's ash (so possibly BSD shs as well) doesn't like it for instance. -- Stephane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
thanx to all for the
Rakesh Sharma wrote: > JyotiC wrote: > > hi > > when writing a sed command as > > sed 's/../../..' filename > > it takes input as some file, > > can a string be given as input as > > sed 's/../../..' string > > > > sed -e 's/.../.../..' << [EOF] > string > [EOF] > > provided the string doesnot contain [EOF] in it. but you can override > this > by storing the string in a variable. > > or we can pipe it: > > var='string' > printf '%s\n' "$var" | sed -e 's/../../..' |
|
![]() |
| Outils de la discussion | |
|
|