Sponsored Content
Full Discussion: Using GNU Regex
Top Forums Shell Programming and Scripting Using GNU Regex Post 302978983 by rthomas529 on Sunday 7th of August 2016 02:44:42 PM
Old 08-07-2016
Using GNU Regex

I'm just learning Regex and while testing my understanding I received some unexpected results.

I created example.txt with the text "abcddd". Running the command
Code:
grep --color '[^abc]d' example.txt

I received the results:
Code:
"abcddd"

with the first and second letter d highlighted in red.


So based on this return my statement meant- search the file example.txt for a string where the first character is not a,b, or c that is followed by the character d and highlight the found characters.

What is confusing is that in my LPIC guide the character ^ represents the start of line. In practice it seems to represent "exclude the following characters". Is there a difference in using it inside the brackets vs. outside brackets?

---------- Post updated at 01:44 PM ---------- Previous update was at 01:25 PM ----------

Apologize I actually found the answer in after reading more carefully.

The use of carat "^a" specifies that the line start with the character "a".

Last edited by vbe; 08-07-2016 at 05:28 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

gnu sed regex grouping not working?

Hello, from the gnu sed manual, I should be able to do this: `\(REGEXP\)' Groups the inner REGEXP as a whole, this is used to: * Apply postfix operators, like `\(abcd\)*': this will search for zero or more whole sequences of `abcd', while `abcd*' ... (3 Replies)
Discussion started by: Allasso
3 Replies

2. Shell Programming and Scripting

regex help

I would like to search strings composed by only one type of charachter for example only strings composed by the charachter 'b' is it right? $egrep '\<(b+)+\>' filename Could be there some side effects? Regards. (1 Reply)
Discussion started by: and77
1 Replies

3. UNIX for Dummies Questions & Answers

regex

I am a newbie. just learning it. I want to create a regex to print the line that has the city, state and the zip code in this form:City, ST 12345 ( Any City, state and a zip code in a file) I tried everything I can, I can't get it to work. Can anyone please help? (3 Replies)
Discussion started by: Pouchie1
3 Replies

4. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

5. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

6. UNIX for Advanced & Expert Users

Vi Regex help

Can someone tell me what is going with this expression :%s/<C-V><C-M>/. Is there a way to get a more useful message if the carriage return has been deleted? http://objectmix.com/editors/149245-fixing-dos-line-endings-within-vim.html#post516826 Why does this expression work for... (1 Reply)
Discussion started by: cokedude
1 Replies

7. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

Help with REGEX??

i have a file 1.txt. the file contains: * server1.com : ewf,wefwef,wef,wef ------------------------------------- * server2.com : ewf,wefwef,wef,wef ------------------------------------- * server3.com : ewf,wefwef,wef,wef ------------------------------------- how can i read * ? from the... (2 Replies)
Discussion started by: zigizag
2 Replies

9. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
charmap(4)						     Kernel Interfaces Manual							charmap(4)

NAME
charmap - symbolic translation file for localedef scripts SYNOPSIS
charmap DESCRIPTION
Invoking the command with the option causes symbolic names in the locale description file to be translated into the encodings given in the charmap file (see localedef(1M)). As a recommendation, a locale description file should be written completely with symbolic names. The charmap file has three sections: a declarations section, a character definition section, and an optional width specification section. Declarations Section Declarations can precede the character definitions. Each consists of the symbol (including the surrounding angle brackets), followed by one or more blanks (or tabs or space characters), fol- lowed by the value of the symbol. Certain declarations are required for multibyte character codesets. For single-byte codesets, all are optional. Following is a list of possible declarations: value Used to declare the name of the coded character set for which the charmap file is defined. This keyword is required for multibyte character codesets. For HP15 encoding scheme, needs to be part of the name. For EUC encoding scheme, needs to be part of the name. value Used to declare the cswidth parameter of the coded character set for which the charmap file is defined (see eucset(1)). value Used to declare the maximum number of bytes in a multibyte character. Defaults to 1 if not given. For multibyte character code- sets, this keyword must be specified. value Used to declare the minimum number of bytes in a character for the encoded character set. The value must be less than or equal to If not given, the default is equal to value Used to declare the escape character, which is used to escape characters that otherwise would have special meaning. If not given, the default is backslash value Used to declare the comment character, which is used to begin comments and should be placed in column one of the charmap file. If not given, the default is the character. Character Definition Section The character-set mapping definitions immediately follow an identifier line containing the string and precede a trailer line consisting of the string (Empty lines and lines beginning with the comment character are ignored.) The character definitions are of two forms. The first form defines a single character and its encoding: encoding A symbolic_name is one or more visible characters from the portable character set as specified by XPG, enclosed in angle brackets. Metacharacters such as angle brackets, escape characters, or comment characters must be escaped if they are used in the name. Two or more symbolic names can be given for the same encoding. The encoding is a character constant in one of four forms: decimal An escape character followed by the letter followed by one to three decimal digits. octal An escape character followed by one to three octal digits. hexadecimal An escape character followed by an followed by two hexadecimal digits. Unicode An escape character followed by a followed by four or five hexadecimal digits. This encoding form can only be used when the option of the command is specified. Multibyte characters are represented by the concatenation of character constants. All constants used in the encoding of a multibyte char- acter must be of the same form. The second form defines a range of characters consisting of all characters from the first symbolic name to the second, inclusive: ... encoding The symbolic name must consist of one or more nonnumeric characters followed by an integer formed of one or more decimal digits. The inte- ger part of the second symbolic name must be larger than that of the first. The range is then interpreted as a list of symbolic names con- sisting of the same character portion and successive integer values from the first through the last. These names are assigned successive encodings starting with the one given. For example, the character definition line is equivalent to: Width Specification The following declarations can follow the character set mapping definitions (after the statement). Each consists of one of the keywords shown in the following list, starting in column 1, followed by the value(s) associated with the keyword, as defined below. A positive integer value (either 1 or 2) defining the column width for the printable character in the coded character set mapping definitions. Coded character set character values are defined using symbolic character names followed by column width values. Defining a character with more than one produces undefined results. The keyword is used to terminate the definitions. Specifying the width of a non-printable char- acter in a declaration produces undefined results. Ellipses (...) can be used between two symbolic character names to specify a range of characters. A positive integer value defining the default column width for any printable character not listed by one of the keywords. If no keyword is included in the charmap, the default charac- ter width is 1. EXAMPLES
For examples, see any of the files under the directory. After the statement, a syntax for a width definition would be: WIDTH <A> 1 <B> 1 <C>...<Z> 1 ... <wc1>...<wcn> 2 END WIDTH In this example, the numerical code point values represented by the symbols <A> and <B> are assigned a width of 1. The code point values <C> to <Z> inclusive, that is, <C>, <D>, <E>, and so on, are also assigned a width of 1. Using <A>...<Z> would have required fewer lines, but the alternative was shown to demonstrate flexibility. The keyword could have been added as appropriate. SEE ALSO
eucset(1), localedef(1M), localedef(4). STANDARDS CONFORMANCE
charmap(4)
All times are GMT -4. The time now is 10:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy