The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to filter out some paragraphs in a file cnlhap Shell Programming and Scripting 7 08-19-2008 03:03 PM
To cut entire column from a file and apend it to another file as another column sakthifire Shell Programming and Scripting 4 06-25-2008 04:27 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
File filter Dastard Shell Programming and Scripting 3 09-06-2007 01:50 PM
filter based on column value rraajjiibb Shell Programming and Scripting 2 05-25-2004 09:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2005
CamTu CamTu is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 46
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 (permalink)  
Old 04-04-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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 (permalink)  
Old 04-04-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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 (permalink)  
Old 04-04-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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.
  #5 (permalink)  
Old 04-04-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0