Try this - there may be smarter and more elegant ways to get what you want, but it may serve as a starting point:
PERFECTLY NAILED IT !!! Thanks a lot..
i know it does everything that was given but i really wish there is some explanation on what is going on.. at least on what did you sort first in term of overall plan until getting such beautiful output..
... .. at least on what did you sort first in term of overall plan until getting such beautiful output..
Thanks for the "beautiful output" - it has been defined by you, hasn't it? Not sure I understand that quote - are you asking for the heuristics applied?
First it is mandatory to look at the input data and the desired output to find out what needs to be eliminated, what propagated and mayhap transformed or converted. Seeing previous attempts (with part successes or failures) always helps. That's why I frequently comment
Quote:
Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.
With above, the basis for a solution is established. Now, build a prototype to see if the logics is close to what is requested, then tweak the solution before finally polishing it... the former gets the logics right, the latter adds e.g. error handling or ergonomy / user friendlyness.
Thanks for the "beautiful output" - it has been defined by you, hasn't it? Not sure I understand that quote - are you asking for the heuristics applied?<br />
<br />
First it is mandatory to look at the input data and the desired output to find out what needs to be eliminated, what propagated and mayhap transformed or converted. Seeing previous attempts (with part successes or failures) always helps. That's why I frequently comment
That is why im interested on how do you plan out all the information given to produce such output.
Quote:
With above, the basis for a solution is established. Now, build a prototype to see if the logics is close to what is requested, then tweak the solution before finally polishing it... the former gets the logics right, the latter adds e.g. error handling or ergonomy / user friendlyness.
Actually im having hard time to sort things out to get the desired output.. my first attempt is to remove the first column and pipe out sort -u to get the uniq 2nd field.. since i dont know awk that deep to store the output somewhere i then output it to some temporary file.txt to call out later.. then i stuck in there to merge the uniq data back with the 1st column (that i have not yet know how to combine the bit )
Last edited by RudiC; 10-18-2017 at 09:04 AM..
Reason: Adapted the quote tags to reflect what I think pedot meant to say...
Explaining heuristics (or a "plan to get from input to output") is not easy a task... First it helps a lot to know the ropes, i.e. what tools do you have at hand, their respective applicability, and what are the strengthes and weaknesses of each that might lean itself to the solution in this special, individual case. Here, awk stood out, but e.g. perl might fit even better - unfortunately, I don't have reasonable command of it.
Now, to the creative and - can I say - intuitive part, which can be a stepwise, repetitive, and approximating approach:
Check features and idiosyncrasies of the input, and what needs to be transported to the output. In this case, we can safely assume the input is sorted - should that not be the case, additional steps might need to be taken. We can identify two entities:
You see: $1 (which is field 1) needs to be split to get at its two elements that need different treatment. The constant part plus a placeholder plus the residual fields go to a working variable X, the numerical part is used to find MIN and MAX values, the latter in successive lines as we assume input is sorted. If the pattern in X changes, the output line is created from the LAST variable, by replacing the placeholder with the actual values, and printed out. At the end of each line's processing, X is saved in LAST.
Please bear in mind that above solution is taylored to the input sample given, so we stop here. Should additional conditions arise, they would need to be programmed in as well in - which may well happen - countless additional steps, conditional statements, loops, special cases, etc.
Explaining heuristics (or a "plan to get from input to output") is not easy a task... First it helps a lot to know the ropes, i.e. what tools do you have at hand, their respective applicability, and what are the strengthes and weaknesses of each that might lean itself to the solution in this special, individual case. Here, awk stood out, but e.g. perl might fit even better - unfortunately, I don't have reasonable command of it.
Now, to the creative and - can I say - intuitive part, which can be a stepwise, repetitive, and approximating approach:
Check features and idiosyncrasies of the input, and what needs to be transported to the output. In this case, we can safely assume the input is sorted - should that not be the case, additional steps might need to be taken. We can identify two entities:
You see: $1 (which is field 1) needs to be split to get at its two elements that need different treatment. The constant part plus a placeholder plus the residual fields go to a working variable X, the numerical part is used to find MIN and MAX values, the latter in successive lines as we assume input is sorted. If the pattern in X changes, the output line is created from the LAST variable, by replacing the placeholder with the actual values, and printed out. At the end of each line's processing, X is saved in LAST.
Please bear in mind that above solution is taylored to the input sample given, so we stop here. Should additional conditions arise, they would need to be programmed in as well in - which may well happen - countless additional steps, conditional statements, loops, special cases, etc.
@RudiC
thanks a lot for such explanation / information..
i got overall general idea but need to understand more on deep level of awk maybe..
I am trying to combine lines with these conditions:
1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text.
2. If condition1 is met then continue to combine lines through a line that ends with a semicolon.
3. Ignore case when matching patterns and remove any... (5 Replies)
Hello all,
i am new to linux , and please need your help and suggestion on....
when vi 1.txt :set list, it looks like
$ is displaying the end of line
Filter: vlan1-BUM-1M $
BUM-1M 0 ... (4 Replies)
Hi,
I am not very familiar with sed and awk and i have a huge file to process which is impossible to do manually. I want to print out beginning from "Network" until end of line only (excluding the Version). AND. the decription to be all in one line.
File:
Version: 2.0 Network: xxx... (9 Replies)
Hi all,
What is the sed command use to combine line?
Example:
Below is an output after extracted from few commands
aaa
bbb
ccc
ddd
eee
fff
ggg
and i would like to combine all the line as shown below,
aaa,bbb,ccc,ddd,eee,fff (5 Replies)
Hi all,
I once knew of a simple unix command to do this, but I can't remember it and I can't find it by searching.
I have two files.
### FILE A ####
A1
A2
A3
A4
A5
### FILE B ####
B1
B2
B3
B4
B5 (2 Replies)
The following input needs to be manipulated as follows:
INPUT from file or results of command:
============start:
Medium identifier : a45c0213:47eb5485:0aec:0321
Medium label : SQL Disk_11516
Location :
Protected : None ... (2 Replies)
I am trying to get some data from a file and print it on the same line.
I have a script that gets the date/time and calculates a DB query call time and sends to a file. I need to take this file and send it in a xcel like format with multiple data columns.
example output file (fndbq.out)
... (3 Replies)
I am new to Unix and have tried to write a ksh script to do the following without success:
I have several reports in a directory (report1, report2, report3, etc). I would like to combine all of these reports into one file (REPORTS). I would like to append *** End of Report *** to each report so... (2 Replies)