LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 02: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 01:53 AM.
 
Old 07-15-2014, 02:37 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,838

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
So if you want all that, maybe you should show us what you've attempted to get it.
 
Old 07-15-2014, 09: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, 10:27 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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 10:29 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:07 PM
Appending text to a series of files - advice wtaicken Programming 9 12-08-2008 05:58 AM
sed - appending text 7stud Linux - Newbie 2 03-01-2007 03:10 PM
Appending to a certain line in text w3stfa11 Programming 5 11-09-2006 10:33 AM
Appending Text Files From Bash Script alts Programming 3 11-18-2004 07:36 PM


All times are GMT -5. The time now is 08:59 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration