Sponsored Content
Top Forums Shell Programming and Scripting Going mad on an egrep command (Reg Expressions) Post 303019456 by Donzo on Friday 29th of June 2018 12:36:35 PM
Old 06-29-2018
Going mad on an egrep command (Reg Expressions)

Dear community,


I am trying for several hours now to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere.


The Textfile contains several thousand lines and has the expression "Lastname" in several lines. Problem is, that there is also expressions like "xLastname" or "abcLastname" in there which I DON'T want to grab.
So the definition of the RegExpression should look like this

EITHER there is no text at all in the line before "Lastname" appears
OR there is Text in the line BUT then a SPACE has to be between the random text and the expression "Lastname"


I tried with ((.+\ )?|(^.))Lastname and ((.+\ )?|(^.*))Lastname and ((.+\ )?|[^.])Lastname and ((.+\ )?|[^.*])Lastname but it always results in the egrep command finding expressions like "abcLastname".


Where is my mistake? The first part (.+\ ) ("If there is text, there HAS to be a SPACE afterwards") seems to work fine but the "OR there is no text at all" does not seem to work.
Wasn't there a special character that I can use to simply check if whatever comes after it is the FIRST expression/character in the line? I cannot find that information online unfortunately.


Thanks to all of you in advance for your help


Best Regards
Donzo

Last edited by Donzo; 06-29-2018 at 02:03 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

SCO vs Linux Reg Expressions Problem

Hi there, I'm investigating migrating a system currently running Scos osr5 to Linux (eg RH 7.2) but there are a lot of in house scripts, some of which are probably using "Sco specific" constructs etc. One I have come across is as follows, if ????? ] then ....etc.etc fi The regular... (2 Replies)
Discussion started by: pcs7088
2 Replies

2. UNIX for Dummies Questions & Answers

reg script command....

hi frnds, i need all ur help guys.. I am facing problem when i give script < file name> command whenever i give this command,i get an error message indicating "Openpty failed. Terminated" :confused: can u help me out... with regds, Deep (7 Replies)
Discussion started by: deep
7 Replies

3. UNIX for Dummies Questions & Answers

Reg getdents command in linux

Hi frnds, i need ur help reg getdents command which is used to read the directory entries. I need to know the exact usage of the command and any sample code reg the usage of getdents command ------------- deep :confused: (1 Reply)
Discussion started by: deep
1 Replies

4. Solaris

doubt reg prstat command

Hi, Can anyone explain me what is RSS time in the prstat output. In the below example 93M is total process size(correct me if am wrong ) what abt 58M? 1693 root 93M 58M cpu1 0 10 4:11:02 0.8% java/35 (2 Replies)
Discussion started by: rogerben
2 Replies

5. Solaris

doubt reg mailx command

Hi, Am trying to send mail from solaris host to my mailbox, but while executing mailx command am getting the follow error.Is this syntax corect? #mailx -s "subject" <myid> The flags you gave are used only when sending mail. (1 Reply)
Discussion started by: rogerben
1 Replies

6. Shell Programming and Scripting

Help with egrep command

Hi All, I am using egrep command to search one pattern. Following is the command i am using egrep -i "ACL*" filename but its also giving me the records which do not contain ACL. any help would be appreciated. Regards, Sam (3 Replies)
Discussion started by: sam25
3 Replies

7. Shell Programming and Scripting

Reg expressions

Hi, I would like to grep for a string within a tag, can someone provide some assistance in how to do it? So I would like to use the grep command to find a string like: <tag>sometext<tag> because the sometext can be any number of characters or an type of number or lettering, what expression... (1 Reply)
Discussion started by: cyberfrog
1 Replies

8. Shell Programming and Scripting

Bash script - coloring reg. expressions in text

Hi all, is there anyone good at bash who will help me? I need to use syntax ${string/pattern/replacement} The problematic part where I am stuck is: #!bin/bash text="A cat is on a mat." exp="cat" newexp="SOMECODEcatSOMECODE" newtext=${${text}/${exp}/${newexp}} == > ERROR "wrong... (4 Replies)
Discussion started by: JohnnyM77
4 Replies

9. Shell Programming and Scripting

Using egrep to output expressions which are not found

Hi, Im using the below command to search a file for multiple expressions if the 4th expression doesnt exist the command simply lists what it can find and ignores what it cant. Is there any way to get the command to output an error or a message if it cant find the 4th expression to a file? ... (16 Replies)
Discussion started by: 02JayJay02
16 Replies

10. Shell Programming and Scripting

Problems with reg.-expressions in a awk-search-pattern

Hi, i have some problems with regular expressions in a awk search pattern. what i want to do: i want to calculate the mean-value in the time from 00:00 to 06:00 how my data looks like: .... 04/01/13-01:40 670992 54802 80711 116460 156177 04/01/13-01:50 703725 60150 85498 ... (3 Replies)
Discussion started by: IMPe
3 Replies
CANONICAL(5)							File Formats Manual						      CANONICAL(5)

NAME
canonical - Postfix canonical table format SYNOPSIS
postmap /etc/postfix/canonical postmap -q "string" /etc/postfix/canonical postmap -q - /etc/postfix/canonical <inputfile DESCRIPTION
The optional canonical(5) table specifies an address mapping for local and non-local addresses. The mapping is used by the cleanup(8) dae- mon, before mail is stored into the queue. The address mapping is recursive. Normally, the canonical(5) table is specified as a text file that serves as input to the postmap(1) command. The result, an indexed file in dbm or db format, is used for fast searching by the mail system. Execute the command "postmap /etc/postfix/canonical" to rebuild an indexed file after changing the corresponding text file. When the table is provided via other means such as NIS, LDAP or SQL, the same lookups are done as for ordinary indexed files. Alternatively, the table can be provided as a regular-expression map where patterns are given as regular expressions, or lookups can be directed to TCP-based server. In those cases, the lookups are done in a slightly different way as described below under "REGULAR EXPRESSION TABLES" or "TCP-BASED TABLES". By default the canonical(5) mapping affects both message header addresses (i.e. addresses that appear inside messages) and message envelope addresses (for example, the addresses that are used in SMTP protocol commands). This is controlled with the canonical_classes parameter. NOTE: Postfix versions 2.2 and later rewrite message headers from remote SMTP clients only if the client matches the local_header_re- write_clients parameter, or if the remote_header_rewrite_domain configuration parameter specifies a non-empty value. To get the behavior before Postfix 2.2, specify "local_header_rewrite_clients = static:all". Typically, one would use the canonical(5) table to replace login names by Firstname.Lastname, or to clean up addresses produced by legacy mail systems. The canonical(5) mapping is not to be confused with virtual alias support or with local aliasing. To change the destination but not the headers, use the virtual(5) or aliases(5) map instead. CASE FOLDING
The search string is folded to lowercase before database lookup. As of Postfix 2.3, the search string is not case folded with database types such as regexp: or pcre: whose lookup fields can match both upper and lower case. TABLE FORMAT
The input format for the postmap(1) command is as follows: pattern result When pattern matches a mail address, replace it by the corresponding result. blank lines and comments Empty lines and whitespace-only lines are ignored, as are lines whose first non-whitespace character is a `#'. multi-line text A logical line starts with non-whitespace text. A line that starts with whitespace continues a logical line. TABLE SEARCH ORDER
With lookups from indexed files such as DB or DBM, or from networked tables such as NIS, LDAP or SQL, patterns are tried in the order as listed below: user@domain address Replace user@domain by address. This form has the highest precedence. This is useful to clean up addresses produced by legacy mail systems. It can also be used to produce Firstname.Lastname style addresses, but see below for a simpler solution. user address Replace user@site by address when site is equal to $myorigin, when site is listed in $mydestination, or when it is listed in $inet_interfaces or $proxy_interfaces. This form is useful for replacing login names by Firstname.Lastname. @domain address Replace other addresses in domain by address. This form has the lowest precedence. Note: @domain is a wild-card. When this form is applied to recipient addresses, the Postfix SMTP server accepts mail for any recipi- ent in domain, regardless of whether that recipient exists. This may turn your mail system into a backscatter source: Postfix first accepts mail for non-existent recipients and then tries to return that mail as "undeliverable" to the often forged sender address. RESULT ADDRESS REWRITING
The lookup result is subject to address rewriting: o When the result has the form @otherdomain, the result becomes the same user in otherdomain. o When "append_at_myorigin=yes", append "@$myorigin" to addresses without "@domain". o When "append_dot_mydomain=yes", append ".$mydomain" to addresses without ".domain". ADDRESS EXTENSION
When a mail address localpart contains the optional recipient delimiter (e.g., user+foo@domain), the lookup order becomes: user+foo@domain, user@domain, user+foo, user, and @domain. The propagate_unmatched_extensions parameter controls whether an unmatched address extension (+foo) is propagated to the result of table lookup. REGULAR EXPRESSION TABLES
This section describes how the table lookups change when the table is given in the form of regular expressions. For a description of regu- lar expression lookup table syntax, see regexp_table(5) or pcre_table(5). Each pattern is a regular expression that is applied to the entire address being looked up. Thus, user@domain mail addresses are not broken up into their user and @domain constituent parts, nor is user+foo broken up into user and foo. Patterns are applied in the order as specified in the table, until a pattern is found that matches the search string. Results are the same as with indexed file lookups, with the additional feature that parenthesized substrings from the pattern can be inter- polated as $1, $2 and so on. TCP-BASED TABLES This section describes how the table lookups change when lookups are directed to a TCP-based server. For a description of the TCP client/server lookup protocol, see tcp_table(5). This feature is not available up to and including Postfix version 2.4. Each lookup operation uses the entire address once. Thus, user@domain mail addresses are not broken up into their user and @domain con- stituent parts, nor is user+foo broken up into user and foo. Results are the same as with indexed file lookups. BUGS
The table format does not understand quoting conventions. CONFIGURATION PARAMETERS
The following main.cf parameters are especially relevant. The text below provides only a parameter summary. See postconf(5) for more details including examples. canonical_classes What addresses are subject to canonical address mapping. canonical_maps List of canonical mapping tables. recipient_canonical_maps Address mapping lookup table for envelope and header recipient addresses. sender_canonical_maps Address mapping lookup table for envelope and header sender addresses. propagate_unmatched_extensions A list of address rewriting or forwarding mechanisms that propagate an address extension from the original address to the result. Specify zero or more of canonical, virtual, alias, forward, include, or generic. Other parameters of interest: inet_interfaces The network interface addresses that this system receives mail on. You need to stop and start Postfix when this parameter changes. local_header_rewrite_clients Rewrite message header addresses in mail from these clients and update incomplete addresses with the domain name in $myorigin or $mydomain; either don't rewrite message headers from other clients at all, or rewrite message headers and update incomplete addresses with the domain specified in the remote_header_rewrite_domain parameter. proxy_interfaces Other interfaces that this machine receives mail on by way of a proxy agent or network address translator. masquerade_classes List of address classes subject to masquerading: zero or more of envelope_sender, envelope_recipient, header_sender, header_recipi- ent. masquerade_domains List of domains that hide their subdomain structure. masquerade_exceptions List of user names that are not subject to address masquerading. mydestination List of domains that this mail system considers local. myorigin The domain that is appended to locally-posted mail. owner_request_special Give special treatment to owner-xxx and xxx-request addresses. remote_header_rewrite_domain Don't rewrite message headers from remote clients at all when this parameter is empty; otherwise, rewrite message headers and append the specified domain name to incomplete addresses. SEE ALSO
cleanup(8), canonicalize and enqueue mail postmap(1), Postfix lookup table manager postconf(5), configuration parameters virtual(5), virtual aliasing README FILES
Use "postconf readme_directory" or "postconf html_directory" to locate this information. DATABASE_README, Postfix lookup table overview ADDRESS_REWRITING_README, address rewriting guide LICENSE
The Secure Mailer license must be distributed with this software. AUTHOR(S) Wietse Venema IBM T.J. Watson Research P.O. Box 704 Yorktown Heights, NY 10598, USA CANONICAL(5)
All times are GMT -4. The time now is 07:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy