0

I have one pattern

cat sample.text

\newline</Text>

I'm using the following command:

sed ':a; N; $!ba; s|\newline</Text>|</Text>|g' sample.text

but following command is not working.

3 Answers 3

2

This might work for you (GNU sed):

sed '$!N;s/\n\(<\/Text>\)/\1/;P;D' file

or

sed -r '$!N;s|\n(</Text>)|\1|;P;D' file

However if \newline is a literal:

sed 's/\\newline\(<\/Text>\)/\1/g' file

or

sed -r 's|\\newline(</Text>)|\1|g' file

Would work just as well.

Sign up to request clarification or add additional context in comments.

Comments

2

Are you just trying to get rid of the newlines before </Text>? That's just a simple substitution:

gawk -vRS='\0' -vORS= '{gsub(/\n<\/Text>/,"</Text>")}1' file

Comments

0

I just found solution myself so thought to share with everyone.

 sed ':a; N; $!ba; s|\\newline<\/Text>|</Text>|g' sample.text

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.