LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-15-2014, 01:30 AM   #1
sam@
Member
 
Registered: Sep 2013
Posts: 31

Rep: Reputation: Disabled
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 .

Last edited by sam@; 07-24-2014 at 12:53 AM.
 
Old 07-15-2014, 01:37 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
So if you want all that, maybe you should show us what you've attempted to get it.
 
Old 07-15-2014, 08:57 AM   #3
sam@
Member
 
Registered: Sep 2013
Posts: 31

Original Poster
Rep: Reputation: Disabled
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
 
Old 07-15-2014, 09:27 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by sam@ View Post
...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.

Last edited by schneidz; 07-15-2014 at 09:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help appending text to file, using variables soupmagnet Linux - Newbie 5 10-02-2012 02:07 PM
Appending text to a series of files - advice wtaicken Programming 9 12-08-2008 04:58 AM
sed - appending text 7stud Linux - Newbie 2 03-01-2007 02:10 PM
Appending to a certain line in text w3stfa11 Programming 5 11-09-2006 09:33 AM
Appending Text Files From Bash Script alts Programming 3 11-18-2004 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration