Sponsored Content
Top Forums Shell Programming and Scripting Regular expression in grep -E | awk print Post 302358142 by terry2009 on Thursday 1st of October 2009 12:07:07 PM
Old 10-01-2009
Thanks, but would this work (this is a snippet of a much much larger script):

Code:
grep -E "[A-Z][0-9]" file.txt | sed 's#.*>\([A-Z][0-9]\).*#1,,,1,\1#' > out.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep : regular expression

guys, my requirment goes like this: I have a file, and wish to filter out records where 1. The first letter is o or O and 2. The next 4 following letter should not be ther I do not wish to use pipe and wish to do it in one shot. The best expression I came up with is: grep ^*... (10 Replies)
Discussion started by: RishiPahuja
10 Replies

2. UNIX for Advanced & Expert Users

regarding grep regular expression

When i do ls -ld RT_BP* i am getting the following list. drwxrwx--- 2 user group 256 Oct 17 10:09 RT_BP809 drwxrwx--- 2user group 256 Oct 17 10:09 RT_BP809.O drwxrwx--- 2 user group 256 Oct 17 10:09 RT_BP810 drwxrwx--- 2user group 256 Oct... (2 Replies)
Discussion started by: ukatru
2 Replies

3. Shell Programming and Scripting

grep with regular expression

Hi, guys. I have one question, hope somebody can give me a hand I have a file called passwd, the contents of it arebelow: *********************** ... goldsimj:x:5008:200: goldsij2:x:5009:200: whitej:x:5010:201: brownj:x:5011:202: goldsij3:x:5012:204: greyp:x:5013:203: ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

4. Shell Programming and Scripting

grep and regular expression

Hi, I am executing a svnlook command to check to see if the following line exists. I need a regular expression to represent the line. A /test/test1/qa/test2/index.html A /test/test1/qa/test3/test.jpg A /test/test1/qa/test3/test1.jpg A /test/test1/qa/test4/test.swf I just need to extract... (9 Replies)
Discussion started by: kminkeller
9 Replies

5. Shell Programming and Scripting

Help with grep / regular expression

Hi, Input file: -13- -1er- -1xyz1- -1xz12- -2ab1- -2ab2-- -143- Code: grep '^*\-' input.txt Wrong output: -13- -1xyz1- -2ab1- -2ab2-- (4 Replies)
Discussion started by: dragon.1431
4 Replies

6. Shell Programming and Scripting

How to print the extended regular expression ?

Hello, How to print the field separator in awk? please see the following code: cat a.txt a 1s 2s 3s 4s b 2s 4s $ awk 'BEGIN{FS==" "} {print $2 $3 }' te 1s2s 2s4s I want to get the following output : 1s 2s 2s 4s How to realize this ? $ cat te a 1s,,2s 3s ... (11 Replies)
Discussion started by: 915086731
11 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. Shell Programming and Scripting

Grep + Regular expression or

Hi , I have few lines like A20120101.ANU.ZIP A20120401.ABC.ZIP A20120105.KJK.ZIP A20120809.JUG.ZIP A20120101.MAT.ZIP B20120301.ANU.XIP I want to filter by 1. Files starting with A and Ending With Z ( ^A.*.ZIP$) 2. And either ANU, or KJK or MAT in the file name. Hope my... (6 Replies)
Discussion started by: Anupam_Halder
6 Replies

9. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

10. UNIX for Beginners Questions & Answers

Grep regular expression

I want to track only below: I am using below, but it doesn't work: (6 Replies)
Discussion started by: proactiveaditya
6 Replies
String::Random(3pm)					User Contributed Perl Documentation				       String::Random(3pm)

NAME
String::Random - Perl module to generate random strings based on a pattern SYNOPSIS
use String::Random; $foo = new String::Random; print $foo->randregex('ddd'); # Prints 3 random digits print $foo->randpattern("..."); # Prints 3 random printable characters or use String::Random qw(random_regex random_string); print random_regex('ddd'); # Also prints 3 random digits print random_string("..."); # Also prints 3 random printable characters DESCRIPTION
This module makes it trivial to generate random strings. As an example, let's say you are writing a script that needs to generate a random password for a user. The relevant code might look something like this: use String::Random; $pass = new String::Random; print "Your password is ", $pass->randpattern("CCcc!ccn"), " "; This would output something like this: Your password is UDwp$tj5 If you are more comfortable dealing with regular expressions, the following code would have a similar result: use String::Random; $pass = new String::Random; print "Your password is ", $pass->randregex('[A-Z]{2}[a-z]{2}.[a-z]{2}d'), " "; Patterns The pre-defined patterns (for use with "randpattern()" and "random_pattern()") are as follows: c Any lowercase character [a-z] C Any uppercase character [A-Z] n Any digit [0-9] ! A punctuation character [~`!@$%^&*()-_+={}[]|:;"'.<>?/#,] . Any of the above s A "salt" character [A-Za-z0-9./] b Any binary data These can be modified, but if you need a different pattern it is better to create another pattern, possibly using one of the pre-defined as a base. For example, if you wanted a pattern "A" that contained all upper and lower case letters ("[A-Za-z]"), the following would work: $foo = new String::Random; $foo->{'A'} = [ 'A'..'Z', 'a'..'z' ]; or $foo = new String::Random; $foo->{'A'} = [ @{$foo->{'C'}}, @{$foo->{'c'}} ]; The random_string function, described below, has an alternative interface for adding patterns. Methods new new max => number Create a new String::Random object. Optionally a parameter "max" can be included to specify the maximum number of characters to return for "*" and other regular expression patters that don't return a fixed number of characters. randpattern LIST The randpattern method returns a random string based on the concatenation of all the pattern strings in the list. It will return a list of random strings corresponding to the pattern strings when used in list context. randregex LIST The randregex method returns a random string that will match the regular expression passed in the list argument. Please note that the arguments to randregex are not real regular expressions. Only a small subset of regular expression syntax is actually supported. So far, the following regular expression elements are supported: w Alphanumeric + "_". d Digits. W Printable characters other than those in w. D Printable characters other than those in d. . Printable characters. [] Character classes. {} Repetition. * Same as {0,}. ? Same as {0,1}. + Same as {1,}. Regular expression support is still somewhat incomplete. Currently special characters inside [] are not supported (with the exception of "-" to denote ranges of characters). The parser doesn't care for spaces in the "regular expression" either. Functions random_string PATTERN,LIST random_string PATTERN When called with a single scalar argument, random_string returns a random string using that scalar as a pattern. Optionally, references to lists containing other patterns can be passed to the function. Those lists will be used for 0 through 9 in the pattern (meaning the maximum number of lists that can be passed is 10). For example, the following code: print random_string("0101", ["a", "b", "c"], ["d", "e", "f"]), " "; would print something like this: cebd BUGS
This is Bug Free(TM) code. (At least until somebody finds one...) AUTHOR
Steven Pritchard <steve@silug.org> SEE ALSO
perl(1). perl v5.10.0 2009-06-11 String::Random(3pm)
All times are GMT -4. The time now is 01:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy