Showing posts with label Regular Expression. Show all posts
Showing posts with label Regular Expression. Show all posts

November 17, 2017

grep regex command to extract key values from a file

\w in regex is word character (ASCII letter, digit or underscore) 

> grep -o '\bNAME ="\w*"' ./file.xml

Output:

Name = "company"
Name = "phone_extension"
......

> grep -o '\bNAME ="\w*"' ./file.xml | awk '{print $2}' | grep -o '\w*'

Output:
company
phone_extension

File
-----

<TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="company" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="30" SCALE ="0"/>
            <TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="phone_extension" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="10" SCALE ="0"/>
            <TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="phone_type" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="30" SCALE ="0"/>
            <TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="pgr_phone" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="30" SCALE ="0"/>

October 13, 2016

Regular expression to remove blank lines

If you are using Notepad++, replace ^[\n\r]+ with nothing in the replace

Regular expression to remove html

Regular expression : ^<.*>

Replace ^<.*> with blank if we use Notepad++

Example:
<option value="/html/A.htm">A
<option value="/html/B.com">B
<option value="/html/C.htm">C

The replace will produce:
A
B
C