Select lines from a file based on a criteria | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Select lines from a file based on a criteria

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-02-2013
Tlcm sam Tlcm sam is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 2 February 2013, 7:52 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Select lines from a file based on a criteria

Hi

I need to select lines from a txt file, I have got a line starting with ZMIO:MSISDN= and after a few line I have another line starting with 'MOBILE STATION ISDN NUMBER' and another one starting with 'VLR-ADDRESS' I need to copy these three lines as three different columns in a separate file.

thanks in advance

my file looks like this


Code:
HOME SUBSCRIBER IDENTIFICATION HANDLING COMMAND <MI_>
<  ZMIO:MSISDN=12345678:;

LOADING PROGRAM VERSION 13.18-0

HLRi      DM1HLR01                  2013-01-31  18:27:51

                SUBSCRIBER INFORMATION:

        INTERNATIONAL MOBILE SUBSCRIBER IDENTITY ... 4324567891234 
        MOBILE STATION ISDN NUMBER ................. 12345678    
        ATTACHED IMSI ..............................                 
        MOBILE STATION CATEGORY .................... OR  
        ROUTING CATEGORY ........................... 22 
        ADDITIONAL ROUTING CATEGORY ................ N    
        SERVICE AREA OF MSISDN ..................... ALL
        ACTIVATION STATUS .......................... A    
        VLR-ADDRESS ................................                 
        SIGNALLING POINT CODE ...................... 00000000
        MSC-ADDRESS ................................                 
        PRIMARY BASIC SERVICE CODE ................. T11
        PRIMARY BASIC SERVICE CODE INDEX ........... 000
        ROAMING PROFILE INDEX ...................... 26
        FRAUD PROFILE .............................. N  
        CALLING LINE IDENTIFICATION ENHANCEMENT .... N
        COMMON MSISDN NUMBER ....................... N               
        OVERRIDE COMMON CLI PARAMETERS ............. N
        CMSISDN IS HUNTING GROUP NUMBER ............ N
        DENY DIRECT CALLS .......................... N
        DENY USSD WITH MEMBER NUMBER ............... N
        DENY DIRECT SMS ............................ N

        ZONE CODES:
                 

        MSC AREA RESTRICTED ........................ N

        HLRU IDENTITY .............................. 6

        HOME COUNTRY CODE .......................... N  
        NETWORK DESTINATION CODE ................... N    


COMMAND EXECUTED


<  ZMIO:MSISDN=98765432134:;

LOADING PROGRAM VERSION 13.18-0

HLRi      DM1HLR01                  2013-01-31  18:27:54

                SUBSCRIBER INFORMATION:

        INTERNATIONAL MOBILE SUBSCRIBER IDENTITY ... 32134567895467 
        MOBILE STATION ISDN NUMBER ................. 98765432134 
        ATTACHED IMSI ..............................                 
        MOBILE STATION CATEGORY .................... OR  
        ROUTING CATEGORY ........................... 52 
        ADDITIONAL ROUTING CATEGORY ................ N    
        SERVICE AREA OF MSISDN ..................... ALL
        ACTIVATION STATUS .......................... A    
        VLR-ADDRESS ................................ 96431324567 
        SIGNALLING POINT CODE ...................... 00000000
        MSC-ADDRESS ................................ 543213456789    
        PRIMARY BASIC SERVICE CODE ................. T22
        PRIMARY BASIC SERVICE CODE INDEX ........... 000
        ROAMING PROFILE INDEX ...................... 6 
        FRAUD PROFILE .............................. N  
        CALLING LINE IDENTIFICATION ENHANCEMENT .... N
        COMMON MSISDN NUMBER ....................... N               
        OVERRIDE COMMON CLI PARAMETERS ............. N
        CMSISDN IS HUNTING GROUP NUMBER ............ N
        DENY DIRECT CALLS .......................... N
        DENY USSD WITH MEMBER NUMBER ............... N
        DENY DIRECT SMS ............................ N

        ZONE CODES:
                 

        MSC AREA RESTRICTED ........................ N

        HLRU IDENTITY .............................. 3

        HOME COUNTRY CODE .......................... N  
        NETWORK DESTINATION CODE ................... N    


COMMAND EXECUTED


Last edited by Scott; 02-02-2013 at 08:03 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 02-02-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 21 October 2014, 9:27 AM EDT
Location: Aachen, Germany
Posts: 4,406
Thanks: 73
Thanked 1,076 Times in 1,015 Posts
PLEASE use code tags as demanded in forum rules!
If the order of the keys is always fixed and as you stat above, try
Code:
awk '/ZMIO:MSISDN|MOBILE STATION ISDN NUMBER/ {printf "%s%s", $0, OFS}    # either pattern matched, print to same line
     /VLR-ADDRESS/                                                        # pattern matched - take default action (print $0)
    ' file
< ZMIO:MSISDN=12345678:; MOBILE STATION ISDN NUMBER .... 12345678 VLR-ADDRESS .....
< ZMIO:MSISDN=98765432134:; MOBILE STATION ISDN NUMBER .... 98765432134 VLR-ADDRESS .... 96431324567

Sponsored Links
    #3  
Old 02-02-2013
Tlcm sam Tlcm sam is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 2 February 2013, 7:52 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

thanks for the reply,

Is there any way that I can insert a critieria that if the numerical in the line


Code:
ZMIO:MSISDN=12345678

matches

the numerical in this line


Code:
MOBILE STATION ISDN NUMBER ................. 12345678

only then the files will be selected otherwise no

Last edited by Scott; 02-02-2013 at 08:04 AM.. Reason: Code tags
    #4  
Old 02-02-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 21 October 2014, 9:27 AM EDT
Location: Aachen, Germany
Posts: 4,406
Thanks: 73
Thanked 1,076 Times in 1,015 Posts
PLEASE use code tags as demanded in forum rules!


Code:
$ awk  '/ZMIO:MSISDN/                  {tmp1 = $0; gsub(/[^0-9]/,"", $NF); key1 = $NF}
        /MOBILE STATION ISDN NUMBER/   {tmp2 = $0; gsub(/[^0-9]/,"", $NF); key2 = $NF}
        /VLR-ADDRESS/ && (key1==key2)  {printf "%s%s%s%s%s\n", tmp1, OFS, tmp2, OFS, $0}
       ' file

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Short program to select lines from a file based on a second file Homa Shell Programming and Scripting 1 11-19-2012 11:27 AM
How to select files based on a criteria? saggiboy10 UNIX for Dummies Questions & Answers 7 06-20-2012 10:46 AM
Merging Lines based on criteria losttouch Shell Programming and Scripting 4 04-10-2012 05:38 AM
remove lines based on score criteria smriti_shridhar Shell Programming and Scripting 2 12-02-2008 12:03 AM
Select records based on search criteria on first column shashi_kiran_v UNIX for Dummies Questions & Answers 2 12-02-2005 12:49 PM



All times are GMT -4. The time now is 03:59 AM.