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 ...
- 29.1k
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 ...
- 15.5k
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
Related Tags
grep × 4909awk × 1078
sed × 931
text-processing × 835
regular-expression × 705
bash × 682
linux × 551
shell-script × 467
find × 354
shell × 344
command-line × 230
search × 147
scripting × 134
files × 125
pipe × 123
cut × 94
string × 88
perl × 79
logs × 72
ls × 67
xargs × 64
macos × 64
wildcards × 62
sort × 61
tail × 59