The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract lines from a file automatically. Please a Help alexcol Shell Programming and Scripting 8 12-16-2006 02:25 PM
How to extract a sequence of n lines from a file 0ktalmagik Shell Programming and Scripting 4 06-29-2006 08:24 PM
How to extract many lines from a file, typically the 1000 last kingkong UNIX for Dummies Questions & Answers 3 11-23-2005 01:20 AM
how to extract a range of lines from a file beilstwh Shell Programming and Scripting 5 07-09-2004 05:20 AM
extract specific lines from file apalex UNIX for Dummies Questions & Answers 2 05-15-2001 06:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-24-2008
Registered User
 

Join Date: Oct 2006
Posts: 22
Script that extract some lines from a file lookin into another

I want a ksh script that parse two files (text files, actually my original files are .xls) - input data:

- one file file1 containig lines separated by spaces (or other delimiter)
- 2nd one file2 contain only one numerical value in a line (for simplicity but it might of the same form as the 1st)
- I know the 2nd value in file1 is also numerical and some of them can be found in file2

Output data:

The result should be a file that contains from the file1 only those lines whose 2nd field cannot be found in any line of file1.


I know this is easy, but I am too tired after a full hard working day so an expert can fix it in a minute.
I think it can be done in one line (complex?) command either....
Reply With Quote
Forum Sponsor
  #2  
Old 01-24-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
sample input files AND desired output based on sample input PLS!
Reply With Quote
  #3  
Old 01-24-2008
Registered User
 

Join Date: Oct 2006
Posts: 22
Quote:
Originally Posted by vgersh99 View Post
sample input files AND desired output based on sample input PLS!

An example of line in file1 is like:



GAGLIARDI 7 GILBERTO TREZZANO - DG 30450 3TECH 3TECH 3TECH


All the lines are of this form.
Column 2 is interesting for me.

file2 might contain in one line only a number let's say 7:
- then do not output the line,
otherwise if 7 does not exist in file2
- then output the line (in a file).


At this moment both files are some .xls containing the same columns.
Reply With Quote
  #4  
Old 01-24-2008
Registered User
 

Join Date: Oct 2006
Posts: 22
Both files contains thousands of lines...
Reply With Quote
  #5  
Old 01-24-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
a sample for file2, pls!
What do you consider a 'column' in file1 and file2?
In your sample file1, the 2-nd column has a value '7'. Is that correct?
Reply With Quote
  #6  
Old 01-24-2008
Registered User
 

Join Date: Oct 2006
Posts: 22
A line in file1:

GAGLIARDI 743 GILBERTO TREZZANO - DG 30450 3TECH 3TECH 3TECH


A line in file2:

GAGLIARDI 743 GILBERTO TREZZANO - DG 30450 SupportCRM TeamLead 3TECH
Reply With Quote
  #7  
Old 01-24-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
assuming file1 and file2 are of the same format:
Code:
nawk 'FNR==NR {file2[$2];next} !($2 in file2)' file2 file1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0