logo
down
shadow

Is it possible to find lines with multiple occurences of the same word with grep?


Is it possible to find lines with multiple occurences of the same word with grep?

By : h_s_bbb
Date : November 17 2020, 11:55 AM
Does that help Is it possible to write a (one line) grep expression to find lines which contain three occurrences of the same word? Note that we don't know the word a priori. The following snippet catches most cases: , This should work for you:
code :
grep -E "[[:<:]](\w+)[[:>:]].*[[:<:]]\1[[:>:]].*[[:<:]]\1[[:>:]]" testfile
paul@horus:~/src/sandbox$ cat testfile
how is summer summer summer ha ha
this summer is a hot summer of summers yes it is
summer summer summer
there is only one summer in this sentence
summer appears as the first and last summer words in this summer
the summertime is always in summer, one of several summers
the summer of which we speak is summery but is a real summer summer, yes
this also works with cats, since there are three cats in these cats, ha!
paul@horus:~/src/sandbox$ grep -E "[[:<:]](\w+)[[:>:]].*[[:<:]]\1[[:>:]].*[[:<:]]\1[[:>:]]" testfile
how is summer summer summer ha ha
summer summer summer
summer appears as the first and last summer words in this summer
the summer of which we speak is summery but is a real summer summer, yes
this also works with cats, since there are three cats in these cats, ha!
paul@horus:~/src/sandbox$ 


Share : facebook icon twitter icon
How to find patterns across multiple lines using grep?

How to find patterns across multiple lines using grep?


By : Shyamsunder Sharma
Date : March 29 2020, 07:55 AM
hope this fix your issue Grep is not sufficient for this operation.
pcregrep which is found in most of the modern Linux systems can be used as
code :
pcregrep -M  'abc.*(\n|.)*efg' test.txt
% sudo port install pcre2 
% brew install pcre
% brew install pcre2
Count word occurences in very large file (memory exhausted on running) grep -o foo | wc -l

Count word occurences in very large file (memory exhausted on running) grep -o foo | wc -l


By : Sylvia Tancheva
Date : March 29 2020, 07:55 AM
help you fix your problem http://lists.gnu.org/archive/html/parallel/2014-07/msg00009.html
EXAMPLE: Grepping n lines for m regular expressions.
code :
grep -f regexps.txt bigfile
grep -F -f regexps.txt bigfile
cat regexp.txt | parallel --pipe -L1000 --round-robin grep -f - bigfile
parallel --pipepart --block 100M -a bigfile grep -f regexp.txt
parallel --pipepart --block 100M -a bigfile --fifo cat regexp.txt \| parallel --pipe -L1000 --round-robin grep -f - {}
grep 3 latest occurences and some lines around the occurence

grep 3 latest occurences and some lines around the occurence


By : user4990928
Date : March 29 2020, 07:55 AM
seems to work fine The output you get is because grep stops printing context (-C) at the next match. I don't see how to make it behave otherwise.
The script below (written on the command-line) reads the whole file and forms an array of lines. Then it goes through it and prints surrounding two lines for each match, or up to start/end of array.
code :
perl -MList::Util=min,max -0777 -wnE'
    @m = split /\n/; 
    for (0..$#m) { 
        if ($m[$_] =~ /exception/) { 
            $bi = max(0,$_-2); 
            $ei = min($_+2, $#m);
            say for @m[$bi..$ei]; 
            say "---" 
         } 
     }
' input.txt
How can I find multiple occurences of a text inside a selection (Word VBA)

How can I find multiple occurences of a text inside a selection (Word VBA)


By : user2228167
Date : March 29 2020, 07:55 AM
Does that help The approach I use is to work with two Range objects: one for the selected text, one for the actual search. For each pass through the loop, after collapsing the search range it's set to the end point of the selection range.
In order to make "copies" of a Range use the Duplicate property.
code :
Sub FindOnlyInSelection()
    Dim rngSel As Word.Range
    Dim rngSearch As Word.Range

    Set rngSel = Selection.Range
    Set rngSearch = rngSel.Duplicate

    Do While rngSearch.Find.Execute(findText:="App.?", MatchWholeWord:=True, Forward:=True) = True
        'routine to change numbering (replace text) and increment counter
        rngSearch.Collapse Direction:=wdCollapseEnd
        rngSearch.End = rngSel.End
    Loop
End Sub
How to grep multiple lines using a .txt vocab, matching only first word as variable?

How to grep multiple lines using a .txt vocab, matching only first word as variable?


By : Shapon
Date : March 29 2020, 07:55 AM
it fixes the issue I'm trying to reduce a .sm file1 - around 10 GB by filtering it using a fair long set of words (around 180.108 items) listed in a text file file2. , join is the best tool for this, not grep/awk:
code :
join -t' ' <(sort file1.sm) <(sort file2.txt) >file3.sm
Related Posts Related Posts :
  • What is Object dictionary in CANOpen?
  • Example of orbBasic Indexed User Variables
  • convert to ABSOLUTE in logback
  • How to conditionally download file using p:fileDownload
  • Error on pod install
  • Set HTTP GET Parameters in Finagle
  • different attack that uses sql injection
  • How can I change my xampp username not as 'root'
  • AMQP Content header payload structure
  • Apache POI formula evaluation not working for Excel IF
  • How can I trace RESTEasy's dispatch?
  • Map Freezes on iOS 7 with Google Maps SDK 1.4
  • Comparing lists, is the subset list within the first list
  • Non-ascii character highlight in Sublime Text 2
  • Installing Magit in Aquamacs
  • Receiving error - System.Net.Mail.SmtpException: 4.3.2 try again later
  • Coreaudio render callback in monotouch
  • The command 'yarn --v' also initiates 'yarn install' and installs packages automatically. Why is this happening?
  • save multiple matches in a list (grep or awk)
  • Can a number register be used in a groff request?
  • Mapping FAQ with RASA for large dataset (2000+)
  • Fragment not receiving LiveData updates after remove + add
  • FitText.js makes text bigger rather than smaller
  • ARM - Implementing stack with load/store multiple register values
  • How to check if a ChromeCast Session is already in progress
  • ngForm inside a Carousel Slide in UI Bootstrap not working
  • Clearing attributes in Tritium
  • "vagrant up" failing: Vagrant VM failed to remain in the running state
  • ftsearch returning empty docs
  • What are the advantages of setting "hive.exec.parallel" to false in Hive ?
  • Creating a root certificate in FiddlerCore
  • How to access app.config in a blueprint?
  • DB2 RECORDSET table name converted to uppercase
  • Resizing the superview according to the subviews
  • IExpress - Disable Compression
  • Getting InvalidProtocolBufferException while running oozie job
  • What are the differences between Play run and start?
  • How can I share props in ReasonReact?
  • Task.Delay is skipped
  • Parsley.js Password Confirm doesn‘t work
  • How to get all registred 'browser:resource' in Plone
  • Overriding page_list controller inside a package in Concrete5.6.1.2
  • Robolectric 2.x - dependent jars are downloading while running the tests
  • Setting Flyout to Main Frame Navigation(Windows 8.1 app store)
  • Build project - Nuget Error
  • How to recover admin password for SonarQube
  • perforce Tagging and labelling files
  • How to pass data from one window to another in Titanium?
  • TeamCity CI - Make custom build output folder
  • Multi-tenant ServiceStack API, same deployment to respond to requests on different hostnames?
  • How to show downshift + popper on top of material-ui dialog?
  • jQuery file upload and RequireJS configuration
  • How to send the result of a select query to a message body of a mail in oracle 10G
  • Worklight common build failing with "Failed to update main HTML file"
  • pg_listening_channels() is not returning the channels name
  • Asset management in ZF2
  • Does the Firefox add-on sdk allow direct modification of the http response byte stream?
  • How to remove menu hardware key from your android app
  • Identifying programming language
  • Use shell commands to find Makefile.am in configure.ac
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org