Questions tagged [search]

search is used for questions relating to searching through the contents of files. For searching for filenames using the locate command use the tag locate.

Filter by
Sorted by
Tagged with
40
votes
2answers
17k views

How to Navigate within bash's Reverse Search?

Bash offers the functionality to reverse search via Ctrl + R. Then one can type in a part of a command it will show a fitting entry from the history. Assume this is my history: vim foo1 vim foo2 # I ...
5
votes
2answers
3k views

grep string where next line does not contain string

I want to search all files inside a directory and its subdirectories for lines containing a certain string, but I want to exclude those results that contain a different certain string in the line ...
2
votes
2answers
73 views

Move the cursor directly to `<keyword>` in a long command line

I often find myself in a long command-line, where it can be a pain to navigate to a specific location in the middle by means of Left-Arrow, Right-Arrow, Alt+B, Alt+F etc. I know that using tmux, I ...
3
votes
2answers
30 views

less: search, but ignoring special characters

I'm trying to view large log files. I have a complex shell script that will take a log file and run it through a tangle of text-mangling commands to insert formatting and colouring, and pipe the ...
3
votes
3answers
77 views

How to find character locations of a string in a file?

I need to search for a string (a sequence of characters) in a file with a certain encoding, typically utf8, but return the character offsets (not byte offsets) of the results. So this is a search ...
0
votes
0answers
30 views

Search all disk images for a file name?

When backing up many SD card images onto a large HDD, I am not sure whether one SD card is already included or not. I would like to search all the images for a file name saved on that card, e.g. ...
0
votes
0answers
22 views

Can't Find Installed Software in Ubuntu Search

I have installed some software from downloaded files (not from a repo) but I would like to be able to find them through the Ubuntu search engine in order to have them available in my task bar. For ...
0
votes
2answers
56 views

How can I search date format in vi?

I want to search date format like 2019-07-12 11:22:33. but, in vi mode, :/2019-07-12 11:22:33 is not executed by white space. how can I search 2019-07-12 11:22:33? (other format is not pretty)
0
votes
1answer
36 views

How can I search terminal output?

Say I type git help to learn about the merge command. I don't want to read all the output just the lines that contain merge and their surrounding lines. I thought this would be a common question but ...
0
votes
2answers
65 views

Find searches only for the first matching entry

I have to find all directory paths with specific subfolders. The search pattern is as follows: find /foo/*/searched_folder/bar -maxdepth 0 -type d ̶I̶t̶'̶s̶ ̶w̶o̶r̶k̶i̶n̶g̶ ̶p̶r̶e̶t̶t̶y̶ ̶w̶e̶l̶l̶ ...
0
votes
1answer
28 views

Use reverse i search to cycle through only commands matching pattern

The contents of the command history file using history | less is: 555 ls 556 ls -a 557 echo "hello" 558 echo "hello again" 559 cd 560 pwd 561 echo "hello hello" 562 ls 563 echo "hello hello hello" ...
0
votes
4answers
51 views

Use grep to search for words beginning with non-word characters

The contents of the file testing.txt are: ls -a cmake --verbose verbose I want to use grep to look through this file and find only the word beginning with "--" i.e. the word "--verbose" However ...
53
votes
10answers
47k views

How can I search history with text already entered at the prompt in zsh?

In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings ...
1
vote
1answer
43 views

How to express `find`'s -writable and -readable tests, when they are not available?

Sometimes on old Linux systems, I experience that find doesn't support -writable and -readable tests, which test whether the file or directory is writable/readable resp. for the current user. Say, I ...
1
vote
1answer
1k views

ripgrep: print only filenames matching pattern

Using ripgrep (rg), can I print only the filenames which match a given pattern? There are two separate things I'm trying to do: Match the pattern to the pathname itself (like ag -g pattern) Match ...
0
votes
2answers
433 views

Searching for URLs with subdomains using grep

I have a file with content similar to: mail.google.com srv1.mail.google.com google.com facebook.com yahoo.com tt.twitter.com I want to search for lines with subdomains. I used this command: grep -e ...
0
votes
2answers
47 views

Searching whole system for files with specific inode [duplicate]

I technically know how to do all these things, but combining it is problematic. Inode is saved in first line of text file (I can eventually read it directly from file), I need results saved to the ...
0
votes
2answers
83 views

How to find more than one space and replace it with one space?

I want to find repeated spaces (more than one) and replace them with one space. I tried: sed -e 's/ []+/ /g' myfile.txt > myfile2.txt This resulted in an empty file. Why? and how to achieve my ...
0
votes
1answer
25 views

How to express beginning and end of line in sed

I want to use sed to replace every '} that comes at the end of the line to "}. I wrote: sed -i -e "s/'}$/\"}$/g" But this replaces it to: "}$. What is wrong? How can I use regex in my sed to express ...
1
vote
1answer
53 views

Search for files using terminal and open with preferred program when clicked?

I would like to somehow create links to files within the terminal from search results found when searching files. Same way you would click a hyperlink within the terminal, but in this case it would be ...
0
votes
1answer
30 views

How to search for a newline that is not preceeded by } and remove it

I want to use sed to search for line breaks that are not preceded by }. The regex for identifying theses cases is: [^}]$ . What I want to say: If the line ended without } then remove the new line. ...
1
vote
2answers
3k views

How do you search and replace multiple lines in KDE Kate?

how do you replace multiple lines of code in Kate? The following is the original text: <div id="image"> <br style="clear: left"/> <br style="clear: left"/> <br style="clear: ...
4
votes
2answers
115 views

Extract Sub-Directory Path from Partially Known Directory

Lets say I've got the following directory structure: base/ | +-- app | | | +-- main | | | +-- sub | | | +-- first | | | | | +-- tib1.ear | ...
1
vote
3answers
39 views

How to list all directory paths including a text?

I need to list all directory paths including a text which is part of thier sub-directories. For example, the text is "tpcc" and I have two paths including tpcc as following: /home/arghy/sampledir1/**...
7
votes
1answer
852 views

ls *.csv --ignore=“*pattern*” returns files which contain “pattern”

Why does ls --ignore not ignoring the pattern? Looking at the below example: mkdir books cd books touch books_abby.csv touch books_karen.csv touch books_david.csv touch books_tom.csv This creates ...
1
vote
0answers
23 views

How do I enable listing of zsh commands as you type

on one of my machines while setting up zsh I seem to have accidentally enabled a pretty useful feature. when I search through command history it actually lists all the matching commands as I type. How ...
3
votes
3answers
147 views

Extract lines that have two or more dots

I need to extract (or count) the lines (in a file) that have two or more dots. The lines should not start with dot (it’s OK if they end with a dot), and there must not be two dots in a row (i.e., the ...
0
votes
4answers
137 views

Removing lines whose first column is duplicated

I have a file where strings are separated by a special string (not a comma or delimiter) e.g. <vvv>. I want to check if all strings in the first field are unique. If duplicate rows for the same ...
5
votes
4answers
6k views

Print only the Nth line before each line that matches a pattern

I'm trying to print only the <N>th line before a search pattern. grep -B<N> prints all the <N> lines before the search pattern. I saw the awk code here that can print only the <N&...
0
votes
1answer
48 views

How to capture two regex

In this command, I want to extract strings that are like *.com or *.net, where * is not a dot. I wrote this: grep -P -E '^[^.]+\.com$ |^[^.]+\.net$' example.csv I get this error: grep: conflicting ...
1
vote
1answer
821 views

How to search “info” page for keyword

I'm currently looking through the "info" page for "ls" command and I want to find all relevant sections that contain the keyword "-l". But I'm not sure how to search for keywords and how to move ...
-1
votes
2answers
72 views

Can we search in a pdf file for pages containing several words in no particular order?

I would like to search in a pdf file for all the pages, each containing several given words in no particular order. For example, I want to find all the pages which contain both "hello" and "world" in ...
3
votes
2answers
573 views

Faster search than find

Is there a way to find things faster than find . I am/was doing :- $sudo find / -perm +4000 But it takes ages to find the required info. and I know that most of the files which would that specific ...
129
votes
14answers
93k views

How can I grep in PDF files?

Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
2
votes
6answers
569 views

Searching strings on files

I've got a bunch on strings which I need to find in a couple of files, for example: string1 string2 stringn file1.txt file2.txt filen.txt Is there an (easy) way to do that in bash? I need to know, ...
31
votes
9answers
3k views

Reading and searching long man pages

I finally got fed up when wanting to read about bash's read and it's -s option with man bash. I found the right spot eventually (around line 4500), but it was a frustrating as usual, since both /read ...
0
votes
0answers
35 views

How to change the newline position [duplicate]

I have a file that contains string in each line. I used this file as an input in a program that reads them automatically. The program seem to not be able to read the strings correctly. I tried to ...
23
votes
3answers
14k views

Search for mail content with Mutt

Is it possible in Mutt to search for specific mail content using built-in functionality? Or, as a last resort, how can I configure grep to be used in Mutt? The documentation only mentions the search ...
37
votes
7answers
9k views

Command-line-friendly full-text indexing?

Is there such a thing as a full-text indexing engine, that can be queried from the command line and ideally wouldn't require using a gui at all ? I'm especially interested in indexing my ebooks and ...
0
votes
2answers
100 views

How to pass multiple dynamic ! -path arguments to find

I have a file which contains a list of directories/files that I want to ignore when searching using find. It looks like this: .git .vim config .vimrc .bashrc This list is not exhaustive and can have ...
8
votes
4answers
7k views

grep how to suppress display of non-matched file?

I am trying to find files containing a specific word using grep. There are many files in the directory (> 500) Command I run $ grep 'delete' * Output validate_data_stage1:0 validate_data_stage2:0 ...
1
vote
3answers
772 views

How to search and replace a string with newlines on commandline in a file

I want to replace all occurrences of a text string in a textfile on command line on CentOS 7.2. Search-string: ).\nPORT Replacement-string: ). \n0 closed ports\nPORT I know, this can be achieved ...
-3
votes
1answer
56 views

awk query for sequential replace a pattern

I found the below awk command to sequentially replace a particular line in a file, but i would like to know how this works. Input:- DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 output:- DS: 1 DS: 2 ...
22
votes
3answers
97k views

Searching for a string on multiple zip files

I am working on SunOS 5.10. I have a folder that contains about 200 zip files. Each zip file contains only one text file in it. I would like to search for a specific string in all the text files in ...
0
votes
1answer
462 views

find: './proc/1/map_files': Permission denied

I am inside a docker container build atop of the image alpine:3.6 and I am trying to find if a directory exists. I get te error, find: './proc/1/map_files': Permission denied This is the commands I ...
0
votes
1answer
41 views

How to extract the first column in a file with multi-character delimeter?

I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the ...
24
votes
7answers
8k views

How to replace current word under cursor in Emacs

How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. ...
6
votes
3answers
6k views

Search for special characters using grep

I want to search for the lines that contains any of the following characters: : / / ? # [ ] @ ! $ & ' ( ) * + , ; = %
4
votes
2answers
381 views

Searching for a string that contains the file name

I have a large set of files in a directory. The files contains arbitrary text. I want to search for the file name inside that particular file text. To clarify, I have file1.py.txt (yeas, two dots .py....
0
votes
0answers
46 views

Gnome Activities search does not find most files

When searching files from Gnome activities search only some files are found. I cannot find a clear pattern in which. All files and folders in home/ are found. Nothing in ~/Picture and ~/Documents are ...