Visit Our UNIX and Linux User Community


Script that extract some lines from a file lookin into another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that extract some lines from a file lookin into another
# 1  
Old 01-24-2008
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....
# 2  
Old 01-24-2008
sample input files AND desired output based on sample input PLS!
# 3  
Old 01-24-2008
Quote:
Originally Posted by vgersh99
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.
# 4  
Old 01-24-2008
Both files contains thousands of lines...
# 5  
Old 01-24-2008
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?
# 6  
Old 01-24-2008
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
# 7  
Old 01-24-2008
assuming file1 and file2 are of the same format:
Code:
nawk 'FNR==NR {file2[$2];next} !($2 in file2)' file2 file1


Previous Thread | Next Thread
Test Your Knowledge in Computers #813
Difficulty: Medium
The CSS RGBA alpha parameter defines the opacity as a number between 1.0 (fully transparent) and 0.0 (fully opaque).
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract lines that have entries in VI file

Dears experts i have UNIX file that contain 4 million lines , i need to extract all lines that have entiries saved in VI file , i have below comand but it takes tooooo long time : for i in `cat file1.csv`; do cat dump | grep -i $i >> file2.csv; done where : file1.csv = VI file that... (12 Replies)
Discussion started by: is2_egypt
12 Replies

2. Shell Programming and Scripting

Extract lines from a file

Hi all; Here is my file which contains a list of files (recent versions of files are in red). This file is dynamic, files versions can change at any time (versions can increment) filename ------------------------------------------------------- ... (8 Replies)
Discussion started by: chercheur111
8 Replies

3. Shell Programming and Scripting

Extract lines from file using keywords using script

Hi I need some lines of text from input file using keywords. Inputfile IP IS 10.238.52.65 pun-ras-bng-mhs-01#context bsnl.in Card Status : 1:0, 2:1, 3:1, 4:1, 5:0, 6:0, 7:0, 8:0, 9:1, 10:0, 11:0, 12:0, 13:0, 14:1, Max Circuits: 1: 0, 2: 32768, ... (5 Replies)
Discussion started by: surender reddy
5 Replies

4. Shell Programming and Scripting

Script needed to extract few lines from file

Hello, I need a utility script or command that will extract the following lines from a file based on a 'word' contain in a line. For example my file contains lot of lines. So if i pass 1800182 to the script/command it should return everything between 1st RequestNetRates tag before it and 1st... (4 Replies)
Discussion started by: jakSun8
4 Replies

5. Shell Programming and Scripting

How to extract certain lines from a file?

Hi guys I have a several thousands line file in the following format: n817 -------------------------------------------------- n842 -------------------------------------------------- n877 -------------------------------------------------- n513 /bb/data/rmt2db.lrl:JBSKDB 31915 75... (4 Replies)
Discussion started by: aoussenko
4 Replies

6. Shell Programming and Scripting

Extract particular lines from a file

Hi all, I have a file with many records with information as given below ID A16L2_HUMAN Reviewed; 619 AA. AC Q8NAA4; A5PL30; B2RPK5; Q658V4; Q6PID3; Q8NBG0; DT 20-MAY-2008, integrated into UniProtKB/Swiss-Prot. DT 20-MAY-2008, sequence version 2. DT ... (1 Reply)
Discussion started by: kaav06
1 Replies

7. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

8. Shell Programming and Scripting

Script to extract certain lines

Hi I have a text file with the following information: # List 1 (first header) test 1 test 2 test 3 ... # Trials (second header) round 1 run 5 ... and so on I want to create a script, which based on some criterias with return only the list of lines between the header. I... (9 Replies)
Discussion started by: nimo
9 Replies

9. Shell Programming and Scripting

how to write shell script to extract lines we want

hi i have a file which is very large . it contains lines in the format below: seed url, html url .... ... seed url, html url i have sort it already. 2010Ϸ*_籩_ żר*24Ļ δŽ_2010Ϸ*_籩_ 2010Ϸ*_籩_ 뱴˹*... (6 Replies)
Discussion started by: rainboisterous
6 Replies

10. Shell Programming and Scripting

Extract lines from a file automatically. Please a Help

hello, hope you can help me: ive got a file called archivos The content or structure of this file is ./chu0/filechu ./chu1/filechu I extract each line from this file manually and redirect to a file, and it Works fine, so the command line is: awk /chu0/ {print $0}' < archivos >... (8 Replies)
Discussion started by: alexcol
8 Replies

Featured Tech Videos