Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k

Grep command in Cygwin Extract matching words with anchors and metacharacters or bracketgrep on Cygwin

formatting
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 179

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>

!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>

!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

(By the way, if it matters, each ENTITY line start with a < but this editor won't let me add it. :)

<!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>
<!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>
<!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz

abc123457.xyz

abc123458.xyz

abc123456.xyz
abc123457.xyz
abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1

grep abc[0-9] file1

grep "abc[[:digit:]]" file1

grep -E abc[[:digit:]] file1
grep abc[0-9] file1
grep "abc[[:digit:]]" file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

Any help would be appreciated.

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>

!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>

!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

(By the way, if it matters, each ENTITY line start with a < but this editor won't let me add it. :)

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz

abc123457.xyz

abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1

grep abc[0-9] file1

grep "abc[[:digit:]]" file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

Any help would be appreciated.

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

<!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>
<!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>
<!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz
abc123457.xyz
abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1
grep abc[0-9] file1
grep "abc[[:digit:]]" file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

added 1 character in body
Source Link

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>

!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>

!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

(By the way, if it matters, each ENTITY line start with a < but this editor won't let me add it. :)

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz

abc123457.xyz

abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1

grep abc[0-9] file1

grep "abc[[:digit:]]]]" file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

Any help would be appreciated.

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>

!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>

!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

(By the way, if it matters, each ENTITY line start with a < but this editor won't let me add it. :)

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz

abc123457.xyz

abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1

grep abc[0-9] file1

grep "abc[[:digit:]] file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

Any help would be appreciated.

I'm using Cygwin so I've been reviewing POSIX regex info.

I'm trying to search through an xml file for a string and I keep getting the entire line but cannot seem to narrow the results to the few characters I'm looking for.

The file (file1) has many instances of:

!ENTITY abc123456 SYSTEM "../blah/abc123456.xyz" NDATA xyz>

!ENTITY abc123457 SYSTEM "../blah/abc123457.xyz" NDATA xyz>

!ENTITY abc123458 SYSTEM "../blah/abc123458.xyz" NDATA xyz>

(By the way, if it matters, each ENTITY line start with a < but this editor won't let me add it. :)

The grep results list the entire line but I'm trying to narrow the results to:

abc123456.xyz

abc123457.xyz

abc123458.xyz

The following successfully give me the lines:

grep -E abc[[:digit:]] file1

grep abc[0-9] file1

grep "abc[[:digit:]]" file1

Since what I'm looking for is not at the beginning or end of a line, ^ and $ don't seem to be useful. Not sure how to anchor what I'm searching for. I've tried quite a few other variations of using grep without success.

Any help would be appreciated.

Source Link
Loading