0

My input file looks like this:

Session: 324098324
Object: dd02:/24
Time: Sat 28 Oct 2017 12:40:41 AM CEST
Status: Error
ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991

Session: 324321
Object: ad02:/24
Time: Sun 13 May 2018 12:00:43 PM CEST
Status: Ok
ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/21857092

Session: 132452
Object: xd01:/24
Time: Sun 08 Jul 2018 12:16:56 PM CEST
Status: Error
ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/21695878

Output should be: [WRONG]

Session: 324098324, Object: ad02:/24, Time: Sat 28 Oct 2017 12:40:41 AM CEST, Status: Error, ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991
Session: 324098324, Object: ad02:/24, Time: Sat 28 Oct 2017 12:40:41 AM CEST, Status: Error, ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991
Session: 324098324, Object: ad02:/24, Time: Sat 28 Oct 2017 12:40:41 AM CEST, Status: Error, ID: 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991

EDIT: I did a big failure with the output format, the above one is not usable as a CSV, i need a format like:

Session, Object, Time, Status, ID
324098324, ad02:/24, Sat 28 Oct 2017 12:40:41 AM CEST, Error, 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991
324098324, ad02:/24, Sat 28 Oct 2017 12:40:41 AM CEST, Error, 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991
324098324, ad02:/24, Sat 28 Oct 2017 12:40:41 AM CEST, Error, 5F2B0121-4F2B-481D-B79F-2DC827B85093/16123991

3 Answers 3

4
awk -v RS='' '{gsub("\n", ", "); print}' input
3
  • Thank you very much, i played around with awk '{ORS=" ";}; !NF{ORS="\n"};1' input but had no idea how to insert the "," as a seperator, i should look more into gsub, thanks again.
    – T-One
    Aug 10, 2018 at 12:15
  • 2
    @T-One if you want to use field / record separators only, try awk -vRS= 'BEGIN{FS="\n"; OFS=", "} {$1=$1} 1' Aug 10, 2018 at 12:18
  • Thanks for the command. I cannot figure out why this is not changing also the last of the \n to ,. Aug 16, 2019 at 8:47
1

paste available? Try

paste -s -d"\t\t\t\t\t\n" file
1
  • CSV = Comma Separate Values Your answer currently provides TSV (Tab Seperate Values) output. This is not what the OP asked for. Feb 17, 2020 at 13:10
0

grep -A4 "Session " myfile | paste -s -d ' \n'

grep finds word session and prints 4 lines after success.

paste converts them to single line.

You can easily set output delimiter by paste -s -d '||||\n' OR paste -s -d ',,,,\n'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.