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
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
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
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
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
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
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
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
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
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
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
XZGREP(1) XZ Utils XZGREP(1)
NAME
xzgrep - search compressed files for a regular expression
SYNOPSIS
xzgrep [grep_options] [-e] pattern file...
xzegrep ...
xzfgrep ...
lzgrep ...
lzegrep ...
lzfgrep ...
DESCRIPTION
xzgrep invokes grep(1) on files which may be either uncompressed or compressed with xz(1), lzma(1), gzip(1), or bzip2(1). All options
specified are passed directly to grep(1).
If no file is specified, then the standard input is decompressed if necessary and fed to grep(1). When reading from standard input,
gzip(1) and bzip2(1) compressed files are not supported.
If xzgrep is invoked as xzegrep or xzfgrep then egrep(1) or fgrep(1) is used instead of grep(1). The same applies to names lzgrep, lze-
grep, and lzfgrep, which are provided for backward compatibility with LZMA Utils.
ENVIRONMENT
GREP If the GREP environment variable is set, xzgrep uses it instead of grep(1), egrep(1), or fgrep(1).
SEE ALSO
grep(1), xz(1), gzip(1), bzip2(1), zgrep(1)
Tukaani 2009-07-05 XZGREP(1)