how to extract fields with sed and regex -


i have input looks this:

[03/jun/applications/somejunk/morejunk/ 200 

and want use sed + regex extract in form:

03/jun 200 

here's regex i'm trying, can't figure out how make extract want.

\([0-9]{2}/[a-za-z]{3}/\).* \([0-9]{3}\) 

any awesome. here's test code:

$ echo "[03/jun/applications/somejunk/morejunk/ 200" | sed 's,\\([0-9]{2}/[a-za-z]{3}/\\).* \\([0-9]{3}\\),\1 \2,g' 

this works

sed 's;\[\([0-9]\{2\}/[a-za-z]\{3\}\)[^ ]*\(.*\);\1\2;' 

$ echo "[03/jun/applications/somejunk/morejunk/ 200" | sed 's;\[\([0-9]\{2\}/[a-za-z]\{3\}\)[^ ]*\(.*\);\1\2;' 03/jun 200 

match 2 digits [0-9]\{2\}
match single slash /
match 3 letters [a-za-z]\{3\}
group them \1 -- parenthesize them
match until space [^ ]*
match after space (including space) , hold in \2
return \1\2
\2 contains space


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -