sed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

avoid automatic newline when writing output


From: Marco R.
Subject: avoid automatic newline when writing output
Date: Wed, 28 Jul 2021 18:27:35 +0000 (UTC)

Hello,
I'm working with a log4j log file which carries HTTP Requests (URI, body, 
headers, ...) among the usual timestamp, thread id and so forth.

I need to preprocess the JSON inside the body of such requests before applying 
other processings to the whole line, hence I need to somehow extract part of 
each line, work on it, put the result in place of the original and write the 
whole line to output.

Or at least that's the way I thought it:

1- read a line
2- copy the text from line start to begin of request body to output
3- extract the request body and send it to an external tool (jq)4- copy the 
external tool result to output
5- copy the remaining text after request body to line end to output
6- process the next line

By playing with the pattern and hold spaces I managed to process the same input 
line multiple times, effectively achieving 2, 3, 4 and 5. But I got stuck on 
writing to output, because 'p' (or better the 'p' flag to the 's' command) 
always added a newline at the text, preventing me to write the partial result 
of each step to a single line in output.

It's the first time I use sed for more than a simple s/x/y job, hence I may 
have missed something from the docs: is there a way to avoid the automatic 
newline addition?

You may find more info (and how I ended up doing it) here: 
https://unix.stackexchange.com/questions/660332/how-to-avoid-sed-outputting-new-line-carriage-return


Regards
Marco R.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]