Re: can this be done(sed)
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
|