2022 Developer Survey is open! Take survey.

New answers tagged

1 vote

How to group and count all lines in a file that contain specific string

uniq -c for count and awk for swap columns: $ uniq -c <<END | awk '{print $2 " " $1;}' AB-9791___Foo AB-9791___Foo DE-9791___Bar END AB-9791___Foo 2 DE-9791___Bar 1 A few ideas is ...
user avatar
2 votes
Accepted

How to group and count all lines in a file that contain specific string

You have to sort the file before. You can use grep and uniq like this: grep '9791' file1 | uniq -c 2 AB-9791___Foo 1 DE-9791___Bar
user avatar
  • 14.9k
0 votes

How to find a multiline partial regex match in multiple files?

Here is a way to do the job with a Perl one-liner. The following code processes files of the current directory that have a names beginning with file, you have to adapt according to the files you want ...
user avatar
  • 14.9k
1 vote

How to grep a line with a backslash at the end of the line?

From "man grep" command: -F, --fixed-strings Interpret PATTERNS as fixed strings, not regular expressions. -o, --only-matching Print only the matched (non-empty) parts of a matching line, ...
user avatar
0 votes
Accepted

Skip a character from character class

Use the following: \b[\x{0600}-\x{063F}\x{0641}-\x{06FF}\x{0750}-\x{077F}]\b \x{0640} is excluded.
user avatar
  • 14.9k
0 votes

grep to find files that contain ^M (Windows carriage return)

Other answers require Bash, this one should not: grep -a -r "$(printf '\r')" Explanation printf '\r' prints a literal carriage return character The wrapping "$(..)" puts the CR ...
user avatar
0 votes

grep file for only part of line

I'd say this is a better and cleaner approach than any of the previous answers: grep -oP 'Order Number :\s*\K[^\r\n]*' 'Extract Text Output.rtf' or grep -oP 'Order Number :\s*\K[A-Z0-9]*' 'Extract ...
user avatar

Top 50 recent answers are included