|
Answer» I want to match 2 REGULAR expressions in a line, separated by some alphanumeric. Please let me know how to use AND in sed. For example: In below text : aaas3435435;; AAA:name 677678777 BBB:address I want to check if the line has string AAA:name and BBB:address
Regular Expressions (Regex) can be a challenge. If you have multiple patterns, you can simply CONTINUE the EXPRESSION to include them. I managed to test this in a Bash environment but will also work in the Windows NT prompt by changing the single quotes to double quotes. The return code ($? in Bash; ERRORLEVEL in Windows) will be zero if the input data MATCHES the Regex and 100 if it does not.
Code: [Select]bash$ echo 'aaas3435435;; AAA:name 677678777 BBB:address' | sed -s '/AAA:name.*BBB:address/!{q100}' aaas3435435;; AAA:name 677678777 BBB:address bash$ echo $? 0
bash$ echo 'aaas3435435;; AAA:name 677678777 CCC:address' | sed -s '/AAA:name.*BBB:address/!{q100}' aaas3435435;; AAA:name 677678777 CCC:address bash$ echo $? 100
Good luck.
|