Printing specified lines only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing specified lines only
# 1  
Old 01-03-2008
Printing specified lines only

hi,
i m having 2 files say F1 and F2.
there are some joining conditions like:

Column 4 from F1= Column 29 from F2;
Column 10 from F1= Column 165 in F2;
and if value in column 8 from F2='3'
than i should get Column 4,5,8,10 from F1 and 29,165 from F2.

I cant provide the files. but the files are pipe-delimited means each column is seperated by |.

please provide me the help in this case.

Thanks
# 2  
Old 01-03-2008
to get quick responses, tell something more about what are you trying to archive
# 3  
Old 01-03-2008
hi,
Actually i have sql queries and with those queries i want to check the feed files in unix.

so i have the joining condition as:
Column 4 from F1= Column 29 from F2;
Column 10 from F1= Column 165 in F2;
and if value in column 8 from F2='3'

so that i can retrieve the value of column 7(in F2) which i need finally.

now can u help me.?
thanks
# 4  
Old 01-03-2008
you need something like:
Code:
#!/usr/bin/perl
# get_col_values.pl
my $file1 = shift;
my $file2 = shift;

open (F1, '<',$file1)  or  die "Failed to read file $file1 : $! \n";
open (F2, '<',$file2)  or  die "Failed to read file $file2 : $! \n";
while (my $line_f1 = <F1>) {
    my $line_f2 = <F2>;

    my @fields_f1 = split (/\|/, $line_f1);
    my @fields_f2 = split (/\|/, $line_f2);

    if (($fields_f1[4] == $fields_f2[29])  and  ($fields_f1[10] == $fields_f2[165])  and  ($fields_f2[8] == 3)) {
        print $fields_f1[4], " ", $fields_f1[5], " ", $fields_f1[8], " ", $fields_f1[10], " ", $fields_f2[29], " ", $fields_f2[165], " ", $fields_f2[7];
    }
}
close (F1);
close (F2);

this perl script is untested, and needs a lot of improvements
# 5  
Old 01-03-2008
hi yogesh,
i m having no idea about perl.
Cant we use simple unix commands in shell and awk to get the result?
Please help me with this.
Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Printing out lines that have the same value in the first column but different value in the second

Hi, I have a text file that looks like the following: ILMN_1343291 6 74341083 74341772 ILMN_1343291 6 74341195 74341099 ILMN_1343295 12 6387581 6387650 ILMN_1651209 1 1657001 1657050 ILMN_1651209 5 83524260 83524309 I... (1 Reply)
Discussion started by: evelibertine
1 Replies

2. Shell Programming and Scripting

printing lines before and after a record

Hello Everyone, I want to print out the records after and before a certain record. I am able to figure out how to print that particular record but not the ones before and after. Looking for some advice Thank you (6 Replies)
Discussion started by: danish0909
6 Replies

3. Shell Programming and Scripting

Printing the lines that appear in an other file, and the three lines after them

Hi ! I need some help with a script I am writing. I am trying to compare two files, the first file being in this format : Header1 Text1-1 Text1-2 Text1-3 Header2 Text2-1 etc... For each header, I want to check if it appears in the second file, and if it is the case print the header... (4 Replies)
Discussion started by: jbi
4 Replies

4. Shell Programming and Scripting

Printing the lines which are repeating in a files

Hi, I need to find the lines which are repeating in a file cat file1 abcdef 23-1 abcdef 24-1 bcdeff 25-0 ttdcfg 26-0 ttdcfg 20-0 bcdef1 25-0 bcdef2 25-0 bcdef3 25-0 bcdef4 25-0 bcdef4 00-0any help is greatly appreciated. Thanks in advance. In need to find which one are... (3 Replies)
Discussion started by: jpkumar10
3 Replies

5. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

6. Shell Programming and Scripting

Printing the lines which proceeds the particular string

Hi, We are facing some issues while finding the particular string. Our file is: cat 1.txt Node Name(s) Preparation fragment Partition: Transformation instance: Transformation: Applied rows: Affected rows: Rejected rows: Throughput(Rows/Sec): Throughput(Bytes/Sec): Last... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

7. Shell Programming and Scripting

Printing coloured lines

I want to print "Hello,How are you" in green colour using printf. How to do so? (5 Replies)
Discussion started by: proactiveaditya
5 Replies

8. Shell Programming and Scripting

selective printing of lines

Hi all , i need to grep for a string in a text file and print the string and the 3rd line above it. As always , Thanks. (4 Replies)
Discussion started by: okiedokie
4 Replies

9. Shell Programming and Scripting

Printing lines with specific awk NF

I have this files: ./frm/lf_mt1_cd.Ic_cell_template.attr ./die/addgen_tb_pumd.Ic_cell_template.attr ./min_m1_n.Ic_cell_template.attr When I use: awk -F\/ '{print NF}' Would result to: 3 3 2 I would like to list the files with 3 fields on it. Any Suggestions? (1 Reply)
Discussion started by: jehrome_rando
1 Replies

10. Programming

Suppress last N lines printing

Hi, I want to know different ways of suppressing printing of last N lines. Can anyone help? Thanks, Sree (1 Reply)
Discussion started by: chakri400
1 Replies
Login or Register to Ask a Question