Sponsored Content
Top Forums Shell Programming and Scripting Awk: Matching Pattern From other file with length Post 302943603 by siramitsharma on Monday 11th of May 2015 04:48:52 AM
Old 05-11-2015
Awk: Matching Pattern From other file with length

Hi,
I have input file whose first column needs(match.txt) to be matched with the first column of the input file with min & max length as defined in match.txt. But conditions are not matching. Please help on the changes in the code below as for multiple enteries in match.txt complete match.txt will be iterated for every line

Inputfile.txt
Code:
 91560606,9132008926661208,20150501000000,S,MTS_TECHZONE,2470,405899136999995,ZTE_20150501000021.4723_MTPP.SMS,postpaid
915612345,9131689141500399,20150501000005,S,MTS_TECHZONE,2376,405899136999995,ZTE_20150501000021.4723_MTPP.SMS,postpaid
915606061,9131689141847478,20150501000008,S,MTS_TECHZONE,2377,405899136999995,ZTE_20150501000021.4723_MTPP.SMS,postpaid
91512130,9132009153417379,20150501000009,S,MTSCC_UTIBAOUT,2471,405899136999995,ZTE_20150501000021.4723_MTPP.SMS,postpaid
91512131,9131638459315908,20150501000009,S,MTSCC_UTIBAOUT,2A65,405899136999995,ZTE_20150501000021.4723_MTPP.SMS,postpaid
9151213,9131899152971817,20150501000001,S,MTSCC_UTIBAOUT,2A6A,405899136999995,ZTE_20150501000051.4724_MTPP.SMS,postpaid
9156060,9131639136042555,20150501000000,S,MTS_TECHZONE,2A65,405899136999995,ZTE_20150501000051.4724_MTPP.SMS,postpaid
91532320,9131878925486546,20150501000000,S,PHONEYTUNES2,2375,405899136999995,ZTE_20150501000051.4724_MTPP.SMS,postpaid

match.txt
Code:
 9156,4,10
 9151,4,7
 91532,5,10

Code
Code:
 awk -F, 'NR==FNR{SHTMINL[$1]=$2;SHTMAXL[$1]=$3;next}
 {
 for(i  in SHTMINL )
 {
 if($1 ~ /^(i)/ && length($1) <= SHTMAXL[$i] && length($1) >= SHTMINL[$i] )
 print
 }
 }
 ' match.txt inputfile.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK pattern matching, first and last

In a nutshell, I need to work out how to return the last matching pattern from an awk //,// search. I can bring back the first, but am unsure how to obtain the last, and a simple tail won't work as the match could be over multiple lines. Secondly I would like some way of pattern matching, a... (10 Replies)
Discussion started by: smb_uk
10 Replies

2. Shell Programming and Scripting

pattern matching using awk.

Dear Team, How do we match two patterns on the same line using awk?Are there any logical operators which i could use in awk like awk '\gokul && chennai\' <filename> Eg: Input file: gokul,10/11/1986,coimbatore. gokul,10/11/1986,bangalore. gokul,12/04/2008,chennai.... (2 Replies)
Discussion started by: gokulj
2 Replies

3. Shell Programming and Scripting

AWK pattern matching

Hi, How can I tell awk to print all lines/columns if column number 5 contains the word Monday? I have tried nawk -F, '$5==Monday' OFS=, myfile > outputfile but that doesn't work (I am a newb!!) Thanks, (7 Replies)
Discussion started by: keenboy100
7 Replies

4. UNIX for Dummies Questions & Answers

awk - pattern matching?

Hello all, I am trying to sort thru a database and print all the customers whose first names are only four characters. I just want to pull the first name only from the database. the database records appear like this in file: Mike Harrington:(510) 548-1278:250:100:175; first is name Mike... (4 Replies)
Discussion started by: citizencro
4 Replies

5. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

6. Shell Programming and Scripting

awk pattern matching

can somebody provide me with some ksh code that will return true if my the contents in my variable match anyone of these strings ORA|ERROR|SP2 variable="Error:ORA-01017: Invalid username/password; logon denied\nSP2-0640:Not connected" I tried this and it does not seem to work for me ... (3 Replies)
Discussion started by: BeefStu
3 Replies

7. Shell Programming and Scripting

Pattern matching using awk

Hi I am trying to find a pattern match with column one containing 3 numbers. input file tmp.lst abcd456|1|23123|123123|23423 kumadff|a|dadfadf|adfd|adfadfadf xxxd999|d|adfdfs|adfadf|adfdasfadf admin|a|dafdf|adfadfa||| output file tmp4.lst abcd456|1|23123|123123|23423... (3 Replies)
Discussion started by: vamsekumar
3 Replies

8. Shell Programming and Scripting

awk pattern matching

I have two files, want to compare file1 data with file2 second column and print line which are not matching. Need help in matching the pattern, file2 second column number can be leading 0 or 00 or 000. Example: file1 1 2 3 file2 a,0001 b,02 c,000 d,01 e,2 f,0005 Expected output:... (20 Replies)
Discussion started by: vegasluxor
20 Replies

9. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

10. Shell Programming and Scripting

Using awk to add length of matching characters between field in file

The awk below produces the current output, which will add +1 to $3. However, I am trying to add the length of the matching characters between $5 and $6 to $3. I have tried using sub as a variable to store the length but am not able to do so correctly. I added comments to each line and the... (4 Replies)
Discussion started by: cmccabe
4 Replies
Device::Gsm::Sms(3pm)					User Contributed Perl Documentation				     Device::Gsm::Sms(3pm)

NAME
Device::Gsm::Sms - SMS message internal class that represents a single text SMS message SYNOPSIS
# A list of Device::Gsm::Sms messages is returned by # Device::Gsm messages() method. use Device::Gsm; ... @sms = $gsm->messages(); if( @sms ) { foreach( @sms ) { print $msg->storage() , " "; print $msg->recipient() , " "; print $msg->sender() , " "; print $msg->content() , " "; print $msg->time() , " "; print $msg->type() , " "; } } # Or you can instance a sms message from raw PDU data my $msg = new Device::Gsm::Sms( header => '+CMGL: ...', pdu => `[encoded pdu data]', storage=> 'ME', # or 'SC' ); if( defined $msg ) { print $msg->recipient() , " "; print $msg->sender() , " "; print $msg->content() , " "; # or $msg->text() print $msg->time() , " "; print $msg->type() , " "; } $msg->delete(); DESCRIPTION
"Device::Gsm::Sms" class implements very basic SMS message object, that can be used to decode "+CMGL" GSM command response to build a more friendly high-level object. METHODS
The following is a list of methods applicable to "Device::Gsm::Sms" objects. content() See text() method. decode() Starts the decoding process of pdu binary data. If decoding process ends in success, return value is true and sms object is filled with all proper values. If decoding process has errors or pdu data is not provided, return value is 0 (zero). delete() Delete the current SMS message from sim card. Example: $gsm = Device::Gsm->new(); ... my @msg = $gsm->messages(); $msg[0] && $msg[0]->delete(); new() Basic constructor. You can build a new "Device::Gsm::Sms" object from the raw +CMGL header and PDU data. Those data is then decoded and a new sms object is instanced and all information filled, to be available for subsequent method calls. The allowed parameters to new() method are: header This is the raw +CMGL header string as modem outputs when you issue a +CMGL command pdu Binary encoded sms data storage Tells which storage to delete the message from. Check the documentation of your phone to know valid storage values. Default values are: "ME" Deletes messages from gsm phone memory. "SC" Deletes messages from sim card. index() Returns the sms message index number, that is the position of message in the internal device memory or sim card. This number is used for example to delete the message. my $gsm = Device::Gsm->new(port=>'/dev/ttyS0'); ... my @messages = $gsm->messages(); ... # Delete the first returned message my $msg = shift @messages; $gsm->delete_sms( $msg->index() ); recipient() Returns the sms recipient number (destination address = DA) as string (ex.: +39012345678). sender() Returns the sms sender number (originating address = OA) as string. status() Status of the message can be one value from the following list: storage() Returns the storage where SMS has been read from. text() Returns the textual content of sms message. token() Returns the given PDU token of the decoded message (internal usage). type() SMS messages can be of two types: SMS_SUBMIT and SMS_DELIVER, that are defined by two constants with those names. type() method returns one of these two values. Example: if( $sms->type() == Device::Gsm::Sms::SMS_DELIVER ) { # ... } elsif( $sms->type() == Device::Gsm::Sms::SMS_SUBMIT ) { # ... } REQUIRES
o Device::Gsm EXPORTS
None TODO
o Complete and proof-read documentation and examples COPYRIGHT
Device::Gsm::Sms - SMS message simple class that represents a text SMS message Copyright (C) 2002-2009 Cosimo Streppone, cosimo@cpan.org This program is free software; you can redistribute it and/or modify it only under the terms of Perl itself. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Perl licensing terms for details. AUTHOR
Cosimo Streppone, cosimo@cpan.org SEE ALSO
Device::Gsm, perl(1) perl v5.14.2 2012-03-08 Device::Gsm::Sms(3pm)
All times are GMT -4. The time now is 08:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy