Unix - need to remove line break from record spanning multiple lines

Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I have a file as below
"IN001~24Apr16~Hi,
what a way?
oh no!~
not here~"
"IN003~29Apr16~
what a way?
~oh no!
say again.
not again~"
and I want the output in below format
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
Any solution using awk or sed is much appreciated.
filesystems
add a comment |Â
up vote
-1
down vote
favorite
I have a file as below
"IN001~24Apr16~Hi,
what a way?
oh no!~
not here~"
"IN003~29Apr16~
what a way?
~oh no!
say again.
not again~"
and I want the output in below format
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
Any solution using awk or sed is much appreciated.
filesystems
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a file as below
"IN001~24Apr16~Hi,
what a way?
oh no!~
not here~"
"IN003~29Apr16~
what a way?
~oh no!
say again.
not again~"
and I want the output in below format
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
Any solution using awk or sed is much appreciated.
filesystems
I have a file as below
"IN001~24Apr16~Hi,
what a way?
oh no!~
not here~"
"IN003~29Apr16~
what a way?
~oh no!
say again.
not again~"
and I want the output in below format
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
Any solution using awk or sed is much appreciated.
filesystems
edited Apr 11 at 18:05
Hauke Laging
53.2k1282130
53.2k1282130
asked Apr 11 at 16:34
Sundeep
4
4
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32
add a comment |Â
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
awk ' printf "%s",$0 ; /"$/ print ""; ;' inputfile
There shall be a newline in the output only if the input line ends with double quotes. Thus this awk code outputs all input lines without a newline. After that it checks whether the input line ends in a " and if so then a newline is output.
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
add a comment |Â
up vote
0
down vote
$ sed -n -e '/^"/h;n;' -e H -e '/"$/g;s/n//g;p;' file
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
The sed command will...
/^"/h;n;: copy all lines that start with"to the hold space (h), overwriting whatever was there, and immediately move on to the next line of input (n).H: Other lines are appended to the hold space./"$/g;s/n//g;p;: If a line ends with", the hold space will be fetched (g) and newlines removed from it (these are added when appending lines to the hold space), and the resulting string is printed.
The command line can be compressed a bit:
$ sed -n '/^"/h;n;;H;/"$/g;s/n//g;p;' file
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
awk ' printf "%s",$0 ; /"$/ print ""; ;' inputfile
There shall be a newline in the output only if the input line ends with double quotes. Thus this awk code outputs all input lines without a newline. After that it checks whether the input line ends in a " and if so then a newline is output.
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
add a comment |Â
up vote
0
down vote
awk ' printf "%s",$0 ; /"$/ print ""; ;' inputfile
There shall be a newline in the output only if the input line ends with double quotes. Thus this awk code outputs all input lines without a newline. After that it checks whether the input line ends in a " and if so then a newline is output.
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
add a comment |Â
up vote
0
down vote
up vote
0
down vote
awk ' printf "%s",$0 ; /"$/ print ""; ;' inputfile
There shall be a newline in the output only if the input line ends with double quotes. Thus this awk code outputs all input lines without a newline. After that it checks whether the input line ends in a " and if so then a newline is output.
awk ' printf "%s",$0 ; /"$/ print ""; ;' inputfile
There shall be a newline in the output only if the input line ends with double quotes. Thus this awk code outputs all input lines without a newline. After that it checks whether the input line ends in a " and if so then a newline is output.
edited Apr 12 at 18:13
answered Apr 11 at 18:08
Hauke Laging
53.2k1282130
53.2k1282130
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
add a comment |Â
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
I really should ask you to qualify this with an explanation, but given my (first) comment underneath the question itself I'm going to OK this from the review queue as is.
â roaima
Apr 11 at 22:16
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
@roaima You seem to imply that correctly working, unique code could be a "very low quality" answer; especially when the question is about a "solution" and not about an explanation. That would be a strange attitude.
â Hauke Laging
Apr 11 at 22:53
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
Not at all. It was flagged in the LQ review queue, possibly because it was an unadorned single line of code. Sufficiently clever code that others could really benefit from an explanation.
â roaima
Apr 11 at 23:01
add a comment |Â
up vote
0
down vote
$ sed -n -e '/^"/h;n;' -e H -e '/"$/g;s/n//g;p;' file
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
The sed command will...
/^"/h;n;: copy all lines that start with"to the hold space (h), overwriting whatever was there, and immediately move on to the next line of input (n).H: Other lines are appended to the hold space./"$/g;s/n//g;p;: If a line ends with", the hold space will be fetched (g) and newlines removed from it (these are added when appending lines to the hold space), and the resulting string is printed.
The command line can be compressed a bit:
$ sed -n '/^"/h;n;;H;/"$/g;s/n//g;p;' file
add a comment |Â
up vote
0
down vote
$ sed -n -e '/^"/h;n;' -e H -e '/"$/g;s/n//g;p;' file
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
The sed command will...
/^"/h;n;: copy all lines that start with"to the hold space (h), overwriting whatever was there, and immediately move on to the next line of input (n).H: Other lines are appended to the hold space./"$/g;s/n//g;p;: If a line ends with", the hold space will be fetched (g) and newlines removed from it (these are added when appending lines to the hold space), and the resulting string is printed.
The command line can be compressed a bit:
$ sed -n '/^"/h;n;;H;/"$/g;s/n//g;p;' file
add a comment |Â
up vote
0
down vote
up vote
0
down vote
$ sed -n -e '/^"/h;n;' -e H -e '/"$/g;s/n//g;p;' file
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
The sed command will...
/^"/h;n;: copy all lines that start with"to the hold space (h), overwriting whatever was there, and immediately move on to the next line of input (n).H: Other lines are appended to the hold space./"$/g;s/n//g;p;: If a line ends with", the hold space will be fetched (g) and newlines removed from it (these are added when appending lines to the hold space), and the resulting string is printed.
The command line can be compressed a bit:
$ sed -n '/^"/h;n;;H;/"$/g;s/n//g;p;' file
$ sed -n -e '/^"/h;n;' -e H -e '/"$/g;s/n//g;p;' file
"IN001~24Apr16~Hi,what a way?oh no!~not here~"
"IN003~29Apr16~what a way?~oh no!say again.not again~"
The sed command will...
/^"/h;n;: copy all lines that start with"to the hold space (h), overwriting whatever was there, and immediately move on to the next line of input (n).H: Other lines are appended to the hold space./"$/g;s/n//g;p;: If a line ends with", the hold space will be fetched (g) and newlines removed from it (these are added when appending lines to the hold space), and the resulting string is printed.
The command line can be compressed a bit:
$ sed -n '/^"/h;n;;H;/"$/g;s/n//g;p;' file
edited Apr 12 at 18:31
answered Apr 11 at 20:12
Kusalananda
102k13199316
102k13199316
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437079%2funix-need-to-remove-line-break-from-record-spanning-multiple-lines%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Your input and output looks similar, can you format it correctly and paste at least two lines for input ...
â Bharat
Apr 11 at 17:32