Hot answers tagged

7 votes
Accepted

How do you get the individual outputs of grep?

As mentioned in comments, grep (a utility for extracting lines from unstructured text documents) is not a tool you want to use for parsing HTML, or structured documents in general. Ideally, you want ...
  • 311k
3 votes
Accepted

grep exact process name in bash script with variable argument

Simply run: pgrep -fl script.sh From man pgrep: pgrep, pkill, pidwait - look up, signal, or wait for processes based on name and other attributes -f, --full The pattern is normally only ...
3 votes

Select all the text or characters between 2 text patterns that are repeating

This, using GNU awk for multi-char RS, RT, and \s shorthand for [:space:], might be what you're looking for: $ awk -v RS='\\s*ttt' 'RT && sub(/.*User\s*/,"")' file abc (iii) 2023 ...
  • 27.2k
2 votes

How do you get the individual outputs of grep?

To add to Kusalananda's answer, if you have more general HTML, you might want to use BeautifulSoup instead of hoping to to convert to XML (not that it doesn't use different XML parsers itself under ...
1 vote
Accepted

Find a string enclosed in spaces or coming from the beginning or end with grep

Try: grep -w -e -someword From man grep: -w, --word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must ...
  • 2,308
1 vote

grep exact process name in bash script with variable argument

In shells that support it, you could use the substring expansion to put the brackets in the right places: name=ffmpeg ps -ef | grep "[${name:0:1}]${name:1}" would run grep "[f]fmpeg&...
  • 128k

Only top scored, non community-wiki answers of a minimum length are eligible