Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple filter on line and reorder line
    primarykey
    data
    text
    <p>My title is a bit confusing because I don't know how to express it in good english.</p> <p>Here's my issue. I'm having a flat file formatted this way: </p> <pre><code>: name1 field1-1: field2:value1-2 field3:"value1-3" field4:{"Value-1-4"} : name2 field2-1: field2:"value2-2" field4:{"Value-2-4"} field3:Value2-3 : name3 field3-1: field3:{"Value-3-3"} field2:value3-2 field4:value3-4 </code></pre> <p>So you can see that it's not a nice file because field does not appear in the same order they can be with different type of value sometimes and more over they are sometime missing. The orginal file is also 5 to 20 fields long. </p> <p>Now here's what I want to have in the end: </p> <pre><code>: name1 field2:value1-2 field4:{"Value-1-4"} : name2 field2:"value2-2" field4:{"Value-2-4"} : name3 field2:value3-2 field4:value3-4 </code></pre> <p>So I know the field I want in the final file and I know the precise order I want them to appear.</p> <p>I tried something like </p> <pre><code>sed "s/(field1:.*)|(field2:.*)/\2\1/g" </code></pre> <p>I know it's not the right synthax but it's for readability. But it do not work because the first match is the only to match that happen and the other group can't match. </p> <p>I guess what I want to do is possible with a lot of <code>awk</code>, but I really don't know how I can do it. I really prefer to use <code>bash</code>, <code>sed</code>, <code>awk</code> and <code>grep</code> but if I have no choice I can I can deal with a bit of <code>Perl</code></p> <p><strong>EDIT:</strong> I may give a simple example but the real file has really different fields name</p> <p>Good night and thank you </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload