Visit Our UNIX and Linux User Community


Regex NOT EQUAL help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex NOT EQUAL help
# 1  
Old 08-13-2009
Regex NOT EQUAL help

I have the following line to text:

ExecuteQueue Name=default ThreadCount=60


I want to write a sed or awk function that eliminates everything before "ThreadCount" without taking into account what is actually in front of ThreadCount. Meaning there may be text in front of "ThreadCount" other than what is currently in front of it now. Basically I am looking for a delete everything NOT EQUAL to <STRING> and I cant seem to find anything like that in any sed documentation.
# 2  
Old 08-13-2009
Code:
echo 'ExecuteQueue Name=default ThreadCount=60' | sed 's/.*\(ThreadCount.*\)/\1/'

# 3  
Old 08-13-2009
Youhave to delete from the start of the line up to ThreadCount
Code:
sed 's/^.*ThreadCount/ThreadCount/'  filename > newfile

# 4  
Old 08-13-2009
Awesome vgersh99, you are my hero! If you have a second, could you explain to me how that is working? Im a sed newb (awk & sed book is in the mail).

---------- Post updated at 03:57 PM ---------- Previous update was at 03:55 PM ----------

Jim yours works as well, thank you very much
# 5  
Old 08-13-2009
Code:
sed 's/.*\(ThreadCount.*\)/\1/'

.* - match any (.) character repeated 0 or more times (*) - sed's regex-s are 'greedy' - therefore it 'grabs' as many characters as possible.

followed by a 'capture' '\(ThreadCount.*\) - capture of 'ThreadCount' followed by any char (.) repeated 0 or more times (*) - in effect captures everything till the end of the line.

\1 - output the FIRST 'capture'.

HTH
# 6  
Old 08-13-2009
Makes sense. Thanks again
# 7  
Old 08-13-2009
If you are not very familiar with regular expressions (or even if you are), I'd recommend this site:

RegExr: Online Regular Expression Testing Tool

Gives you the opportunity to see the result of your reg exp, as well as explains what each part of the reg exp is doing

Previous Thread | Next Thread
Test Your Knowledge in Computers #556
Difficulty: Easy
Making mistakes in programming is inevitable.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

awk not equal

Did I do something wrong with this awk not equal? For some reason it prints twice. >awk '{if ($4 != "root") print $1 " " $4 " " $5}' ls_test server10: njs nodeadm server10: njs nodeadm >grep server10 ls_test server10: drwxr-sr-x. 18 njs nodeadm 4096 Aug 16 09:42 /opt > (2 Replies)
Discussion started by: cokedude
2 Replies

2. 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

3. 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

4. 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

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. Shell Programming and Scripting

while [ $x -ge 50 ] + and equal to zero ; then

while + and equal to zero ; then what to punt instead of phrase and equal to zero. it's bash thank you in advance (1 Reply)
Discussion started by: losh
1 Replies

7. Shell Programming and Scripting

My Values are Equal but They are Not

Does anybody understand why this is not being interpreted as true. Script: #!/bin/bash errored=`grep "errored" new_update_scripts.txt` echo $errored = "errored" if ; then echo true else echo false fi Output: $ UpdateScripts errored = errored false (7 Replies)
Discussion started by: scottwmackey
7 Replies

8. Shell Programming and Scripting

equal to operator

Hi, I have the below script executed arg="dir" if "$arg" = "dir" then echo "true" else echo "false" fi Please let me know what happens in the if command. My output is: dir: dir: No such file or directory false which is not the desired output. When i used test command... (1 Reply)
Discussion started by: anijan
1 Replies

9. Solaris

Stop+A equal

Hi, I have replaced my current Intel PC machine with Solaris 10, it use to have windows XP. I am sure alot of people already done this and i have seen Solaris running smoothly but having keyboard problem. What is the equal keys in a QWERTY keyboard for selection <Stop+A> ? Is there a... (5 Replies)
Discussion started by: tlee
5 Replies

Featured Tech Videos