07-26-2019
Hi balajesuri,
Thank you for providing a solution.
In this case can you explain why the question mark is needed in (?!Clear)
I understand that !Clear means do not match clear, but would like some clarification on ? preceding it.
Thanks.
--- Post updated at 02:51 PM ---
Dear balajesuri,
I have found the solution after checking further online, posting here for others to have a look.
(?!) is a regex construct known as negative lookahead.
example: match a q not followed by a u. Negative lookahead provides the solution: q(?!u). The negative lookahead construct is the pair of parentheses, with the opening parenthesis followed by a question mark and an exclamation point.
Reference:
Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions
However I just noticed the machine on which I need to execute this script does not support "grep -P." Can you help me out with an alternative solution? (sed/awk) is ok.
Thanks.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I wanted to put "|" this sign at starting and at end of every field but its not working with first field like
Currently the out put is :
abc | abc | abc |
xyz | xyz | xyz |
But I want the out put in this form:
| abc | abc | abc |
| xyz | xyz | xyz |
plz help me. (2 Replies)
Discussion started by: akash
2 Replies
2. Shell Programming and Scripting
hi
i am running script which contains the commmnds and i am redirecting the script output to a file.
like
./script 1> result.txt 2>&1
the above redirection is not working for commands when run in background in a script.
but the problem here result.txt containg output which is repeated.... (3 Replies)
Discussion started by: raji
3 Replies
3. Solaris
Hi All,
OS-Type=Sun-OS 5.8 Sparc9 Processor
Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)?
For example here we need to monitor logs of live traffic.The data obtained from "tail -f LiveTrafficData.log"
looks something like this:-... (3 Replies)
Discussion started by: Sujan Banerjee
3 Replies
4. Shell Programming and Scripting
echo '0x3f 0xfa ae 0xeA' | sed '/0x/ y/abcdef/ABCDEF/'
output:
0x3F 0xFA AE 0xEA
echo '0x3f 0xfa ae 0xeA' | sed -r '/0x{2}/ y/abcdefg/ABCDEFG/'
output:
0x3F 0xFA AE 0xEA
my expected output:
0x3F 0xFA ae 0xEA
What I want to achieve is change all hexadecimals to UPPER case(only those... (6 Replies)
Discussion started by: kevintse
6 Replies
5. Shell Programming and Scripting
Hello Guys,
I am working on a script and using the below code to fetch the list of all repositories
CHDIR='/mnt/scm/subversion/'
repolist()
{
cd ${CHDIR}
Repo=`ls|cut -d " " -f1`
echo $Repo
}
Output of the above code is
BSB CIB COB DCI DIB DSB ESB-P ESB-TOOLS FareVerify GCACHE GWY... (15 Replies)
Discussion started by: rohit22hamirpur
15 Replies
6. Shell Programming and Scripting
Below is the my cide which is working fine but I am not getting the output indesired format.there is some problem in alignment.Can someone help me to correct this?
if ];
then
summary=$(
echo -e "Please review the log file of auto coloclean utility.\n";
echo -e... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies
7. Shell Programming and Scripting
currently I have process from a raw file to this stage
ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID")
ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID")
ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies
8. Shell Programming and Scripting
Am in need of your help to get the desired output.
nameSECURITY.SERVICES.CONFIG:GETVALUEisPrefetchedNsAccessLast2013-09-13 10:50:13 MESTsAccessTotal1sRunningcHitLastnamePUBLIC.SERVER:INVOKEisPrefetchedNsAccessLast2013-09-17 15:02:05... (5 Replies)
Discussion started by: rocky2013
5 Replies
9. Shell Programming and Scripting
Hi guys.
I have a file containing some hosts and their IPs.
host host1 192.168.2.10
host host2 192.168.2.11
host host3 192.168.2.12
I am writing a script where I want to print these values in 1 line. My script looks like
RUNTIME_NODE=`cat hosts.properties | grep host`
for i in... (7 Replies)
Discussion started by: Junaid Subhani
7 Replies
10. Shell Programming and Scripting
I am searching for a process that should be up and running. Im using the following command
ps -ef | grep elasticsearch
to get
elastic+ 1673 1 0 Jan29 ? 05:08:56 /bin/java -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies
grep(1) General Commands Manual grep(1)
Name
grep, egrep, fgrep - search file for regular expression
Syntax
grep [option...] expression [file...]
egrep [option...] [expression] [file...]
fgrep [option...] [strings] [file]
Description
Commands of the family search the input files (standard input default) for lines matching a pattern. Normally, each line found is copied
to the standard output.
The command patterns are limited regular expressions in the style of which uses a compact nondeterministic algorithm. The command patterns
are full regular expressions. The command uses a fast deterministic algorithm that sometimes needs exponential space. The command pat-
terns are fixed strings. The command is fast and compact.
In all cases the file name is shown if there is more than one input file. Take care when using the characters $ * [ ^ | ( ) and in the
expression because they are also meaningful to the Shell. It is safest to enclose the entire expression argument in single quotes ' '.
The command searches for lines that contain one of the (new line-separated) strings.
The command accepts extended regular expressions. In the following description `character' excludes new line:
A followed by a single character other than new line matches that character.
The character ^ matches the beginning of a line.
The character $ matches the end of a line.
A . (dot) matches any character.
A single character not otherwise endowed with special meaning matches that character.
A string enclosed in brackets [] matches any single character from the string. Ranges of ASCII character codes may be abbreviated
as in `a-z0-9'. A ] may occur only as the first character of the string. A literal - must be placed where it can't be mistaken as
a range indicator.
A regular expression followed by an * (asterisk) matches a sequence of 0 or more matches of the regular expression. A regular
expression followed by a + (plus) matches a sequence of 1 or more matches of the regular expression. A regular expression followed
by a ? (question mark) matches a sequence of 0 or 1 matches of the regular expression.
Two regular expressions concatenated match a match of the first followed by a match of the second.
Two regular expressions separated by | or new line match either a match for the first or a match for the second.
A regular expression enclosed in parentheses matches a match for the regular expression.
The order of precedence of operators at the same parenthesis level is the following: [], then *+?, then concatenation, then | and new
line.
Options
-b Precedes each output line with its block number. This is sometimes useful in locating disk block numbers by context.
-c Produces count of matching lines only.
-e expression
Uses next argument as expression that begins with a minus (-).
-f file Takes regular expression (egrep) or string list (fgrep) from file.
-i Considers upper and lowercase letter identical in making comparisons and only).
-l Lists files with matching lines only once, separated by a new line.
-n Precedes each matching line with its line number.
-s Silent mode and nothing is printed (except error messages). This is useful for checking the error status (see DIAGNOSTICS).
-v Displays all lines that do not match specified expression.
-w Searches for an expression as for a word (as if surrounded by `<' and `>'). For further information, see only.
-x Prints exact lines matched in their entirety only).
Restrictions
Lines are limited to 256 characters; longer lines are truncated.
Diagnostics
Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files.
See Also
ex(1), sed(1), sh(1)
grep(1)