LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Appending text files (https://www.linuxquestions.org/questions/linux-newbie-8/appending-text-files-4175511126/)

sam@ 07-15-2014 01:30 AM

Appending text files
 
Hi I have a text file wherin I want to compare entries with respect to 1st and 4th column.

I want the record with the lowest start value and highest end value .

syg00 07-15-2014 01:37 AM

So if you want all that, maybe you should show us what you've attempted to get it.

sam@ 07-15-2014 08:57 AM

I tried this:

awk -F '[ |]*' '
{
(($2 FS $5) in b) {
b[$2 FS $5] = sprintf("| %s | %s | %s | %s | ", $2, $3, $4, $5)
e[$2 FS $5] = sprintf(" | %s | %s |", $8, $9)
m[$2 FS $5] = $6
M[$2 FS $5] = $7
next
}
{if($6 < m[$2 FS $5]) m[$2 FS $5] = $6
if($7 > M[$2 FS $5]) M[$2 FS $5] = $7
}
END { for(i in b) printf("%s%s | %s%s\n", b[i], m[i], M[i], e[i])
}' inputfile > output

schneidz 07-15-2014 09:27 AM

Quote:

Originally Posted by sam@ (Post 5204032)
...i want my output as
Code:

"PDK_30s1189731L001"        "-1"        "1"        "3"        "999"        "7531"        "9808"        "c"

I want the record with the lowest start value and highest end value ...

these 2 statements dont co-relate. shouldnt column 6 of PDK_30s1189731L001"..."3" be 4454 ?

i would move move column 4 rite next to column 1 so you can scrape it like a key and grep/sed/awk against it and move it back later.


All times are GMT -5. The time now is 04:45 PM.