Re: Insert the content of a file (with command r?)
Werfgam Nadler <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
============insert.sed==============
/regexp/{
h # hold the existing pattern
s/.*// # delete the existing match
# read in the file
r file.txt
g # return the text we held
}
====================================
-tim
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
Hi,
Not sure if that is a bug, but here is a round about solution.
Data file.
$ cat data.txt
data1
data2
############ Begin of MySed.sed##############
G;
/\n$/s:::
/\n./{
# Here instead of 4 you can use your pattern.
/^.*4.*\n.*4.*$/!{
s/\(.*\)\n\(.*\)/\2\n\1/;
x; s/.*//; x;
b;
}
# Use your pattern here instead of 4.
/^.*4.*\n.*4.*$/{
P; s/\n.*//; h;
#Read ur file here
r data.txt
d
}
}
#Use ur pattern instead of 4
/4/{
h
#Read ur file here.
r data.txt
d
}
########### End of MySed.sed####################
output when using seq 10 | sed -f MySed.sed
1
2
3
data1
data2
4
5
6
7
8
9
10
This works even with two succesive lines of same regexp.
but will fail if the last line i.e $ has the regexp.
thanks
Nadler
[Non-text portions of this message have been removed]