Is there another way to achieve this?
how get short phrase in a sentence with character count of 100 to 155 words end with period but don't end something like 50,000. .
Here's my current script but the output is not good. This will use for my snippets or preview.
grep '.\>.\{100,155\}' trim.txt -m 1
The quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the P50,000.00 lazy dog near the bank of the river. The quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the lazy dog near the bank of the river.
What I want the output is this:
The quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the P50,000.00 lazy dog near the bank of the river.
#cat test.txt
The quick brown fox jumps.
The quick brown fox jumps over the lazy dog near the bank of the river.
The quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the P50,000.00 lazy dog near the bank of the river. The quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the lazy dog near the bank of the river.
The quick brown fox jumps over the lazy dog near the bank of the riverThe quick brown fox jumps over the lazy dog near the bank of the riverThe quick brown fox jumps over the lazy dog near the bank of the river The quick brown fox jumps over the lazy dog near the bank of the river
The quick brown fox jumps over the lazy dog near the bank of the river.
sed -n 's/\(.\{99,154\}[^0-9]\.\).*/\1/p' test.txt
Get 99..154 characters followed by a non-digit followed by a dot, match the rest, substitute the entire match by the part that matches the expression in \( \). Suppress the default print, print if match succeeded.
Thanks for the reply, is working but the script print all matches on the range I only need the first match. is there additional to your script to work?, like in
Sure.
If it matches the pattern within the slashes execute the actions within the block {}. The block actions are, replace empty for the first matched group and print and quit.
The Perl line does it, almost the same way but in a less cryptic way. $& is the pattern matched.
Let's add a beginning of line anchor `^' to prevent the possibility of matching from the middle of the line.