filter out certain column from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filter out certain column from a file
# 1  
Old 04-04-2005
filter out certain column from a file

Hi all,

I have this file, how can i remove the ID Number and Cardholder Name from the file ?

Code:
[?25h[?4l[?1l[?3h[?3h
                                                                                                               Mon Apr 4 2005 5:12PM
                                                                                                                              Page 1
                                                                                                                               
                                                     Location Log Recall Report                                                     
                                          Sun Apr 3 2005 11:06AM to Mon Apr 4 2005 12:00AM                                          
 __________________________________________________________________________________________________________________________________ 
|                                                                                                                                  |
| Locations: 599 Parker's II 016869517              Transactions: Valid    Transaction Type: All            Reader Status: Online  |
|__________________________________________________________________________________________________________________________________|
|        |       |T|          |Reader|                   |                    |                     |M|O|O|                | Trans |
|  Date  | Time  |P| Location | Name |     ID Number     |  Cardholder Name   |       Action        |N|F|K|     Reason     |Amount |
 __________________________________________________________________________________________________________________________________ 
|04/03/05|01:43PM|1|Parker II |Park 2|000735219          |Regnier, Michael    |Credit/Debit Spending| | |Y|                |  10.00|
|04/03/05|06:01PM|1|Parker II |Park 2|000676759          |Stevenson, Aren     |Credit/Debit Spending| | |Y|                |  11.32|
|04/03/05|07:00PM|1|Parker II |Park 2|000728866          |Culbreth, Anna      |Credit/Debit Spending| | |Y|                |   4.06|
 __________________________________________________________________________________________________________________________________ 

                                                          Blackboard Inc.                                                        End


Thanks

CT
# 2  
Old 04-04-2005
If this is the whole file and the data is on line 1:
Code:
awk ' {
             if(NR>1) 
             {
                 print $0
             }
        } ' filename > tmp
mv tmp filename

# 3  
Old 04-04-2005
I never have a need to write such a thing and don't write anything complex in awk but here is a stab and I think it meets your requirements (they were ambiguous in my mind so you have two solutions). I am absolutly certain this is too clumsy and can be written more elegantly.

If you are trying to blank the two fields:
Code:
awk -F\| '
    NF != 15 {
        print $0
    }
    NF == 15 && $4 == "T" || $4 == "P" {
        print $0
    }
    NF==15 && $4 != "T" && $4 != "P" {
        printf ("%s%s%s\n",substr($0,1,38),"                   |                    |",substr($0,80))
    }' yourreportfile.rpt

If you want to extract the two fields:
Code:
awk -F\| '
    NF==15 && $4 != "T" && $4 != "P" {
        printf ("%s\t%s\n",$7,$8)
    }' yourreportfile.rpt

# 4  
Old 04-04-2005
if "Credit/Debit Spending" or some other category will always be in the "Action" field ...
Code:
awk '/Debit/ || /Credit/  || /other_category/ {print $7, $8}' yourfile

# 5  
Old 04-04-2005
Quote:
Originally Posted by tmarikle
I am absolutly certain this is too clumsy and can be written more elegantly.
I told you someone could write it more elegantly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CSV File:Filter duplicate records from column1 & another column having unique record

Hi Experts, I have csv file with 30, 40 columns Pasting just 2 column for problem description. Need to print error if below combination is not present in file check for column-1 (DocumentNumber) and filter columns where value in DocumentNumber field is same. For all such rows, the field... (7 Replies)
Discussion started by: as7951
7 Replies

2. Shell Programming and Scripting

Filter duplicate records from csv file with condition on one column

I have csv file with 30, 40 columns Pasting just three column for problem description I want to filter record if column 1 matches CN or DN then, check for values in column 2 if column contain 1235, 1235 then in column 3 values must be sequence of 2345, 2345 and if column 2 contains 6789, 6789... (5 Replies)
Discussion started by: as7951
5 Replies

3. Shell Programming and Scripting

Filter tab file based on column value

Hello I have a tab text file with many columns and have to filter rows ONLY if column 22 has the value of '0', '1', '2' or '3' (out of 0-5). If Column 22 has value '0','1', '2' or '3' (highlighted below), then remove anything less than 10 and greater 100 (based on column 5) AND remove anything... (1 Reply)
Discussion started by: nans
1 Replies

4. Shell Programming and Scripting

Filter file to remove duplicate values in first column

Hello, I have a script that is generating a tab delimited output file. num Name PCA_A1 PCA_A2 PCA_A3 0 compound_00 -3.5054 -1.1207 -2.4372 1 compound_01 -2.2641 0.4287 -1.6120 3 compound_03 -1.3053 1.8495 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

5. Shell Programming and Scripting

UNIX command -Filter rows in fixed width file based on column values

Hi All, I am trying to select the rows in a fixed width file based on values in the columns. I want to select only the rows if column position 3-4 has the value AB I am using cut command to get the column values. Is it possible to check if cut -c3-4 = AB is true then select only that... (2 Replies)
Discussion started by: ashok.k
2 Replies

6. Shell Programming and Scripting

Filter first column duplicates

Dear All, I really enjoy your help or suggestion for resolving an issue. Briefly, I have a file like this: a b c a d e f g h k g h x y z If the first column has the same ID, for example a, just remove it. The output should be this: f g h k g h x y z I was thinking to do it... (11 Replies)
Discussion started by: giuliangiuseppe
11 Replies

7. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

8. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

9. UNIX for Dummies Questions & Answers

Solaris - Filter columns in text file and adding new column

Hello, I am very now to this, hope you can help, I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered... (8 Replies)
Discussion started by: jpbastos
8 Replies

10. Shell Programming and Scripting

filter based on column value

I have a file with colon separated values.. the sample is attached below. No of fields in each record/line is dependent on the value of field53. What I need to do is to design a special filter based on specific requirement of some match of values in particular column or combination of columns. ... (2 Replies)
Discussion started by: rraajjiibb
2 Replies
Login or Register to Ask a Question