Tag Info

New answers tagged

6

Try this: touch -d"April 13 3 AM" file1 touch -d"April 13 9 AM" file2 find . -newer file1 ! -newer file2 -exec grep -l "pcV6URY" {} + rm file1 file2 How it works find can work directly with times but touch handles human-style dates better: touch -d"April 13 3 AM" file1; touch -d"April 13 9 AM" file2 This creates two files to mark the beginning and end ...


0

I solved this one for me using grep and -A option with another grep. grep first_line_word -A 1 testfile | grep second_line_word The -A 1 option prints 1 line after the found line. Of course it depends on your file and word combination. But for me it was the fastest and reliable solution.


-2

$ man -K "fopen" gives you the output /usr/share/man/en/man3/fclose.3.gz? [ynq] y to open/display man page n to continue search q to Quit search


2

Use the global apropos option in man. -K, --global-apropos Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if you can, you should specify a section to reduce the number of pages that need to be searched. Search terms may be simple strings (the default), or regular expressions if the ...


5

From man man: -K, --global-apropos Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if you can, you should specify a section to reduce the number of pages that need to be searched. Search terms may be simple strings (the default), or regular expressions if the --regex ...


0

Putting together the pieces from the other discussion here here's a quick function you can leave in your .bashrc that will get you directly to the built-in (if it exists). Otherwise it opens man as normal: man() { case "$(/bin/bash -c 'type -t '"$1")" in builtin) LESS=+?"^ $1 " command -p man bash ;; *) ...


1

Grepping for non-ASCII characters is easy: set a locale where only ASCII characters are valid, search for invalid characters. LC_CTYPE=C grep '[^[:print:]]' myfile If you want to search for Japanese characters, it's a bit more complicated. With grep, you'll need to make sure that your LC_CTYPE locale setting matches the encoding of the files. You'll also ...


0

My files were encoded in iso-8859-1 so anything that tried to read the input in my default locale (utf-8) would not recognize the Japanese characters. In the end I managed to solve my problem with the following command: env LC_CTYPE=iso-8859-1 grep -nP '[\x80-\xff]' ./* -P is to allow for the Perllike syntax for character ranges. -n is for printing the ...


1

If you don't mind using perl, it has more extensive Unicode support in the form of classes such as {Katakana} and {Hiragana} which I don't think are currently available in even in those versions of grep that provide some PCRE support. However it does appear to require explicit UTF-8 decoding e.g. perl -MEncode -ne 'print if decode("UTF-8",$_) =~ ...


0

Try this: grep '[^[:print:][:space:]]' (Depending on your locale setting maybe you have to prepend it by LANG=C.)


2

You can write a search provider — see this documentation. But that won't change the application search. The default search is built-in, and it orders applications by frequency, which, from this source file, we can see is stored in ~/.local/share/gnome-shell/application_state. From the source, the algorithm is: /* The ranking algorithm we use is: every time ...


0

Try: $ case "$(head -n 1 < file)" in (*pattern*) echo Match ;; esac Match


0

Do you want the list of full strings as a result, or do you want a list of files that contain the string? This would search line number one(-n1) of shell scripts(*.sh) and collect the strings containing 'bash': head -n1 *.sh | grep bash > fullstring.txt fullstring.txt would contain something like this: #!/bin/bash #!/bin/bash


0

Here is a perl onliner to do just that perl -ne 'print if /MY_SEARCH_STRING/; exit' myfile.txt This is going to check if the keyword MY_SEARCH_STRING is present in the first line of the file myfile.txt. If you need to search in the entire file just remove exit from the oneliner.


0

I have implemented the comment of @Rob and succeeded to get the desired result. Replace string by your string. grep -Rin "string" . | grep ":1:.*string" > result.txt This does a recursive case-insensitive search for string in the current directory and prints the line numbers. Then it searches for occurrences in files which are on line 1 and saves the ...


0

Here is a (bad) example of a perl-script that would do something like this: #!/usr/bin/perl -w foreach (@ARGV) { my $filename = $_; open my $file, '<', $filename; my $line = <$file>; close $file; print "$filename\n" if $line =~ /your-match-text/; }



Top 50 recent answers are included