Discussion: can this be done(sed)
Afficher un message
Vieux 21/08/2006, 11h28   #3
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
 
Page generated in 0,05869 seconds with 9 queries