lundi 15 avril 2019

sed behaves differently when getting script from file

I need to extract strings that may contain \n sequence from a file.
Note that in this case \n is not a newline, but simply the sequence of two characters: a backslash followed by a lowescase n.
As an example, if I type:
echo garbage "useful \n string" garbage | sed -e s/.*\(\"[^\"]*\"\).*/\1/
the result is correclty:
"useful \n string"

If instead I save the sed command to a file (b.txt) and type:
echo garbage "useful \n string" garbage | sed -f b.txt
which should do the same thing, instead I don't see any match, and the result is:
garbage "useful \n string" garbage

Note that the file contains just the sed command, the input string, still comes from the stdin.

I am using GNU sed version 4.2.1 in a windows 10 command line window
Any suggestion?

Aucun commentaire:

Enregistrer un commentaire