Sponsored Content
Top Forums Shell Programming and Scripting awk with multiple regex and substring Post 302540509 by millan on Thursday 21st of July 2011 01:30:41 AM
Old 07-21-2011
awk with multiple regex and substring

Hi Experts,

I have a file on which i want to print the line which should match following criterias.

Line should not start with 0 or 9
and
Line should start with 1
and
(
576th character should not be 1 or 2
or
576-580 postion should not be NIPPF or CDIPB
or
576-581 postion should not be CDUSPF
)

I have written below code,but it is not displaying correct result though not giving any error. Please help me and thanks in advance.

Code:
/usr/bin/nawk '!/^[09]/ && /^1/ && ((substr($0,576,1) !~ "[12]")||(substr($0,576,5) !~ "NIPPF|CDIPB")||(substr($0,576,6) !~ "CDUSPF"))' a.txt >> result.txt


Last edited by Franklin52; 07-21-2011 at 03:58 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies

2. UNIX for Dummies Questions & Answers

substring using AWK

can we do substring fuctionality using AWK say I have string "sandeep" can i pick up only portion "nde" from it. Thanks and Regards Sandeep Ranade (3 Replies)
Discussion started by: mahabunta
3 Replies

3. Shell Programming and Scripting

Substring using sed or awk

I am trying to get a substring from a string stored in a variable. I tried sed with a bit help from this forum, but not successful. Here is my problem. My string is: "REPLYFILE=myfile.txt" And I need: myfile.txt (everything after the = symbol). My string is: "myfile.txt.gz.20091120.enc... (5 Replies)
Discussion started by: jamjam10k
5 Replies

4. Shell Programming and Scripting

Getting substring with awk

Hi Team, How to get the last 3 characters of a String irrespective of their length using awk? Thanks Kinny (5 Replies)
Discussion started by: kinny
5 Replies

5. UNIX for Dummies Questions & Answers

Multiple Substring Outputs

Hello, I am reading a file with millions of lines in it. Each line is big line containing several xml tags. I need to Output just the value of two tags in a seperate flat file. For eg- I need to output whats present in <ComponentName> something </ComponentName> and another tag is... (2 Replies)
Discussion started by: sunnybehl
2 Replies

6. UNIX for Dummies Questions & Answers

awk to match multiple regex and create separate output files

Howdy Folks, I have a list that looks like this: (file2.txt) AAA BBB CCC DDD and there are 24 of these short words. I am matching these patterns to another file with 755795 lines (file1.txt). I have this code for matching: awk -v f2=file2.txt ' BEGIN { while(... (2 Replies)
Discussion started by: heecha
2 Replies

7. Shell Programming and Scripting

AWK: Substring search

Hi I have a table like this I want to know how many times the string in 2nd column appears in the first column as substring. For example the first string of 2nd column "cgt" occurs 3 times in the 1st column and "acg" one time. So my desired output is THank you very much in advance:) (14 Replies)
Discussion started by: polsum
14 Replies

8. UNIX for Advanced & Expert Users

awk if/substring/append help

Hi All, I need some help with an awk command: What I'm trying to do is append "MYGROUP: " to text with the substring "AT_" the input file follows this format: AT_xxxxxx Name1 Name2 AT_xxxxxx NameA NameB I want the output to be: MYGROUP: AT_xxxxx Name1 Name2 MYGROUP:... (2 Replies)
Discussion started by: bikecraft
2 Replies

9. Shell Programming and Scripting

Regex: Extract substring between 2 separator

Hi Input: aa-bb-cc-dd.ee.ff.gg Output: dd I want to get the word after the last '-' until the first dot I have tried with regex lookbehind and lookahead like this: (?<=-).*(?=\.) but his returns too much bb-cc-dd.ee.ff (7 Replies)
Discussion started by: chitech
7 Replies

10. Shell Programming and Scripting

Multiple regex in sed

I am using the following sed script to remove new lines (\r\n and \n), except from lines starting with >: sed -i ':a /^>/!N;s/\r\n\(\)/\1/;s/\n\(\)/\1/;ta' Is there a way to include both \r\n and \n in one regex to avoid the second substitute script (s/\n\(\)/\1/)? (4 Replies)
Discussion started by: Xterra
4 Replies
regex.h(3HEAD)							      Headers							    regex.h(3HEAD)

NAME
regex.h, regex - regular expression matching types SYNOPSIS
#include <regex.h> DESCRIPTION
The <regex.h> header defines the structures and symbolic constants used by the regcomp(), regexec(), regerror(), and regfree() functions. See regcomp(3C). The structure type regex_t contains the following member: size_t re_nsub number of parenthesized subexpressions The type size_t is defined as described in <sys/types.h>. See types.h(3HEAD). The type regoff_t is defined as a signed integer type that can hold the largest value that can be stored in either a type off_t or type ssize_t. The structure type regmatch_t contains the following members: regoff_t rm_so byte offset from start of string to start of substring regoff_t rm_eo byte offset from start of string of the first character after the end of substring Values for the cflags parameter to the regcomp function are as follows: REG_EXTENDED use extended regular expressions REG_ICASE ignore case in match REG_NOSUB report only success or fail in regexec() REG_NEWLINE change the handling of NEWLINE character Values for the eflags parameter to the regexec() function are as follows: REG_NOTBOL The circumflex character (^), when taken as a special character, does not match the beginning of string. REG_NOTEOL The dollar sign ($), when taken as a special character, does not match the end of string. The following constants are defined as error return values: REG_NOMATCH regexec() failed to match. REG_BADPAT Invalid regular expression. REG_ECOLLATE Invalid collating element referenced. REG_ECTYPE Invalid character class type referenced. REG_EESCAPE Trailing '' in pattern. REG_ESUBREG Number in fIdigit invalid or in error. REG_EBRACK "[]" imbalance. REG_EPAREN "()" or "()" imbalance. REG_EBRACE "" imbalance. REG_BADBR Content of "" invalid: not a number, number too large, more than two numbers, first larger than second. REG_ERANGE Invalid endpoint in range expression. REG_ESPACE Out of memory. REG_BADRPT '?', '*', or '+' not preceded by valid regular expression. REG_ENOSYS Reserved. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
regcomp(3C), types.h(3HEAD), attributes(5), standards(5) SunOS 5.11 9 Sep 2004 regex.h(3HEAD)
All times are GMT -4. The time now is 12:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy