0

I have a text file with the following format

 Type: XTREMIO
  UID: 51,4f,0c,51,9d,00,05,22
  Vendor: XtremIO
  Product: XtremApp
  Size: 10.00 GB
  Name: knocknarea_jounal
  Replication info: [rpa_A, RPA_B, knocknarea_jounal]
  Array Serial: CKM00150400153
  RPA To volume paths map: None



 Type: XTREMIO
  UID: 51,4f,0c,51,9d,00,05,28
  Vendor: XtremIO
  Product: XtremApp
  Size: 5.00 GB
  Name: test_rep
  Replication info: N/A
  Array Serial: CKM00150400153
  RPA To volume paths map: None

My objective is to convert those block into row like this with a delimiter:

XTREMIO;51,4f,0c,51,9d,00,05,28;XtremIO;XtremApp;5.00 GB;test_rep;CKM00150400153
6
  • 3
    Welcome to Stack Overflow. SO is a question and answer page for professional and enthusiastic programmers. Please add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself Commented May 30, 2020 at 13:48
  • there are 2 sets of data in the original file but only one set of data in the result ... what's the logic for determining which set of data to ignore? some of the fields are missing ... what's the logic for ignoring fields? what do you need to do with the results ... just dump to stdout? or save in a variable (or array)? Commented May 30, 2020 at 13:53
  • @markp-fuso "Type;UID;Vendor;Product;Size;Name;Replication info;Array Serial;RPA To volume paths map;" seems no field is missing and nothing ignored, so the logic is clear (hopefully the first colon and newline are always separator). guess the output is saved in some csv text file Commented May 30, 2020 at 14:16
  • 1
    @alecxs; Replication Info: N/A => no N/A in the ouput; RPA To Volume Paths map: None => no None in the output; total of 9 fields in source but only 7 fields in output ... so 2 fields ignored; also, how do you explain 2 sets of data in source but only 1 set of data in ouput? accidentally left out one set or one set left out by design (ie, additional logic used to filter out certain sets of data)? Commented May 30, 2020 at 14:21
  • @markp-fuso true thx for clarifying, makes sense. OP should add N/A;CKM00150400153;None; in example output and mention if there is any logic for filtering duplicate entries (for example same UID) Commented May 30, 2020 at 14:26

1 Answer 1

1

Normally, you should post the code you have written up to know, even if it is not working, so that we can help you instead of working in place of you.

However, there is trivial solution calling awk twice. Assuming your input file is called input, you could try/

awk 'BEGIN{FS = ": "}{print $2}' input | awk 'BEGIN{RS = ""; FS = "\n"; OFS = ";"}{print $1, $2, $3, $4, $5, $6, $8}'

Output:

XTREMIO;51,4f,0c,51,9d,00,05,22;XtremIO;XtremApp;10.00 GB;knocknarea_jounal;CKM00150400153
XTREMIO;51,4f,0c,51,9d,00,05,28;XtremIO;XtremApp;5.00 GB;test_rep;CKM00150400153

Explanation: the first instance of awk is removing everything in the begin of each line until and including the string ": ".

The second one is using the paragraph mode of awk setting the record separator RS to the null string, which means that a record is each set of lines with no blank line, and sets the field separator FS to a newline character. It reads records and outputs the fields as they are, but changing the field separator and the record separator into resp. ";" and a single newline (option by default for ORS).

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

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.