Alphabetical sort for multi line records contains in a single file
Hi all,
I So, I've got a monster text document comprising a list of various company names and associated info just in a long list one after another. I need to sort them alphabetically by name...
The text document looks like this:
Company Name:
the_first_company's_name_here
Address:
an_address_here
Phone:
phone_number_here
SomeOtherValue:
the_value_here
Name:
the_next_name_here
Address:
the_second_company's_address_here
Phone:
phone_number_here
SomeOtherValue:
another_value_here
etc.
If I only wanted to alphabetically sort the names then that would be a simple:
but that doesn't help me rearrange all the other bits of data associated with each Company Name. My grasp of regular expressions is woefully poor... is there a simple way to chop up the file into separate records by using the line "Company Name:" to signal the start of each new record, alphabetically sort the values for each Company Name: field, and then reassemble the document with all the other bits of each record in the right place?
The value for each field is always on the line immediately below it. Each record is of varying length, as some lack certain fields (e.g., not all will have a SomeOtherValue: field, or whatever). Some have data across multiple lines. The only things that are common throughout are the Company Name: field which is ALWAYS at the start of a new record, and the fact that there are always 3 empty lines immediately preceding each "Company Name:" label as in the example above.
Does anybody have an elegant solution for this? Or a not-so-elegant solution?
One thought is to put each record on one line.
If each company name preceded by-
Then
Add the ~ so can later force new-line. Get rid of extra new-lines by replacing with ^. Make the ~ into new lines so every record now on one line.
Do your sort. Then
to put the new-lines back in there.
Thanks for your help. Your solution didn't work for some reason - it messed up something that meant everything reassembled completely out of order. I have a feeling there may have been some irregularities in my data after all.. Anyway, I managed to bodge together a fix in C so it's all good
I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line
Source file
07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Hi All,
I have one file containing thousands of table names in single column. Now I want that file split into multiple files e.g one file containing table names starting from A, other containing all tables starting from B...and so on..till Z.
I tried below but it did not work.
for i in... (6 Replies)
Hi,
I have a file like mentioned below..For each specific id starting with > I want to join the sequence in multiple lines to a single line..Is there a simple way in awk or sed to do this
>ENST00000558922 cdna:KNOWN
TCCAGGATCCAGCCTCCCGATCACCGCGCTAGTCCTCGCCCTGCCTGGGCTTCCCCAGAG... (2 Replies)
Hi,
My Oracle query is returing below o/p
----------------------------------------------------------
Ins trnas value
a lkp1 x
a lkp1 y
b lkp1 a
b lkp2 x
b lkp2 y ... (7 Replies)
Now that I've parsed out the data that I desire I'm left with variable length multi-line records that are field seperated by new lines (\n) and record seperated by a single empty line ("")
At first I was considering doing something like this to append all of the record rows into a single row:
... (4 Replies)
Some records in a file look like this, with any number of lines between start and end flags:
/Start
Some stuff
Banana 1
Some more stuff
End/
/Start
Some stuff
End/
/Start
Some stuff
Some more stuff
Banana 2
End/
...how would I process this file to find records containing the... (8 Replies)
Hi,
Can anyone know how to use perl to merge the following multi-line information which beginning with "BAM" into one line. For each line need to delete the return and add a space. Please see the red color line.
******Org. Multi-line)
BAM admin 101.203.57.22 ... (3 Replies)
I am an Awk newbie and cannot wrap my brain around my problem:
Given multi-line records of varying lengths separated by a blank line I need to skip the first two lines
of every record and extract every-other line in each record unless the first line of the record has the word "(CONT)" in the... (10 Replies)