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
0
votes
2answers
1k views

Grep a string from the same file in multiple .tar.gz files [duplicate]

I have multiple *.tar.gz files. They all contain files with file name a, b, and c. Is there a way to grep string 'foo' only from file b under these multiple *.tar.gz files without extracting the files....
2
votes
0answers
420 views

reverse-i-search not showing all results compared to grep

I have always used reverse-i-search to grab my old commands, however for some reason its not returning all the results, at least the results I am expecting. desired command cat ~/.bash_history | ...
5
votes
4answers
3k views

Trying to use `pwd` inside an alias giving unexpected results [duplicate]

If I want to search a file in the system I use the following command: sudo find `pwd` -name filename.ext I want to make an alias for an easier word like search, so I used the command: alias search "...
2
votes
2answers
209 views

How do I force ag (the silver searcher) to list empty files

How do I get ag to list all files, including empty ones? +ravi@boxy:~$ mkdir new && cd new +ravi@boxy:~/new$ echo stuff > non-empty && touch empty +ravi@boxy:~/new$ ag -ul non-...
0
votes
1answer
244 views

Why is ag printing blank lines from this file?

I want to use ag to print the classes and their methods in a python file. I thought that this would be easy using: ag --context=0 --nocolor -os '^\s*(def|class)\s+[_A-Za-z]*' prog.py but for reasons ...
3
votes
0answers
1k views

Kate can't show some newline characters using escape sequences

Kate and KWrite both don't show all \n characters. Problems appear to be next to where there are empty lines. The problem isn't just in the highlighting itself. Wrong number of matches are found. ...
4
votes
2answers
12k views

How to extract lines from a text file that contains strings from a list in another file? [duplicate]

I have a file containing population information for a bunch of towns. I have another file that is a list of the names of a subset of those towns. I want to select the population information from the ...
3
votes
2answers
662 views

How do I find files with multiple empty lines?

For replacing multiple empty lines with just one I need to find which files to apply this in the first place, in a big repository. How do I do that?
1
vote
2answers
464 views

list files with similar names sorted by similarity [closed]

Is it possible to search files and list them descending by similarity ? e.g.: Following files are in /: heo HELLO helo hello When I search for 'hello' I would like to have a List like: hello ...
3
votes
0answers
122 views

Using ack to effectively search and RStudio project directory

I'm interested in running ack search on a RStudio project directory that mostly contains *.R script files but also some project files and often *.git files. Directory The project folder structure ...
1
vote
3answers
736 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 ...
2
votes
1answer
108 views

What command(s) can I use in a terminal to find a program that does a particular thing? [duplicate]

I often find myself alt-tabbing to google "How to do X in Linux". Is there a way to search (say, man pages) in Linux to find tools that might be of use in a particular situation? For example, ...
2
votes
1answer
823 views

Search for files inside multiple subdirectories and zip directories [duplicate]

I need to extract more than 2k files from 1000 folders..the problem is, each folder has a zipped folder inside and inside this folder, there is another folder called "fileholder" which contains some ...
2
votes
1answer
338 views

read patterns from file1 and search them iteratively in file2

I'd like to read patterns from file1 and search them iteratively in file2, printing the matched line plus 3 rows, and print them to file3. Now I am doing: cat file1 | while read line; do awk '/$...
3
votes
2answers
646 views

How to open a file in VIM and move cursor to the search result

Consider the file tmp.txt whose contents are: x abcd I want to open it in VIM and move cursor to the c character. So I run VIM with the arguments: $ vim -c "/c" tmp.txt But it sets the cursor on a....
1
vote
1answer
97 views

how to search file for begin of string and save a variable

i am trying to find a way of searching a file for string, it needs to work by searching then file and if any line in the file begin with what i am searching for, then take that whole line and save it ...
0
votes
3answers
181 views

Vim Search and Replace - Regex

I want to perform a search and replace. A newline before any non-digit should be replaced with tab. I tried %s/\n\D/\t/g but it replaced the first character of the word following the newline, which ...
1
vote
3answers
636 views

How to search a text file for a specific integer

Is there a simple way to search a text file (source code) for all instances of a specific integer. This should not trigger on larger numbers that happen to include the integer as a sub-string, but it ...
2
votes
1answer
1k views

How can i replace multi line string using sed? [closed]

I have tried the following command:- [root@10 bin]# cat temp asdjahskjdhajksdhjkashjahfksjdhfkjsddhflkdsjhfklsdajhfklajshdkjalsdlkjasdhkljas hskdajkdhkjas cast $recv $UE_CAPABILITY_ENQUIRY ...
0
votes
0answers
63 views

To forward-search in Raspbian's Bash?

Keybinding CTRL-S is enabled by default in Debian/Ubuntu/OS X bun not in Raspbian. I can enable the reverse-search by in $HOME/.bashrc, which disables XON/XOFF, but it does not help with the forward-...
1
vote
2answers
891 views

search for files with specific text and copy these files to another directory

How do I search for files in a directory that contain a specific text and copy them to another directory ? I am using .ksh shell.
1
vote
1answer
43 views

changing a specific 'column' inside a txt file

I have a file with thousands of entries like this: 6/05/2016,32,34,40,45,48,,01,10 10/05/2016,02,26,27,40,49,,05,10 13/05/2016,07,15,28,31,42,,10,11 17/05/2016,15,27,32,36,39,,03,10 I want to ...
0
votes
1answer
396 views

how to print the count of matched /unmatched patterns and print multiple patterns separated by line

how to print the count of matched /unmatched patterns and print multiple patterns separated by line. Input example (test.log): This 23 line has eight 8888 This 11 line has three 3333 need 12 to ...
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&...
1
vote
1answer
249 views

How to set default personality for a kernel?

I'm trying to replace a 32-bit kernel with a 64-bit one on a 32-bit system, so that I had the complete support for 64 bits for the apps which need it (provided they have the necessary libraries or are ...
2
votes
2answers
2k views

How to extract a function from file? [closed]

I am looking for a command to extract a C function from my code. It would be something like: $ grep -func "MyFunction" foo.c int MyFunction(int i) { return i+1; } I know we can extract it with ...
0
votes
2answers
50 views

searching a file [closed]

I want to find in the system a file, and I know part name of it. How could I do that? I tried unsuccessfully the command: find / "*partname*" The problem is probably very easy however I cannot find ...
3
votes
1answer
4k views

How to search a log file in Linux and escape special characters like square brackets (i.e. [ and ])

How to search a log file in Linux and escape special characters like square brackets (i.e. [ and ]) Can someone point me in the right direction on this? I less the log file as per below: less ...
7
votes
1answer
3k views

grep --exclude does not exclude my file

I am searching a dir for a particular string (to see all instances of where the string is present and in which files). However, I want to exclude one particular file from being searched. Here's what ...
1
vote
1answer
66 views

bash - isolating uppercase words

So, I have a directory containing around 50 directories having for name 3 letter uppercase words: AXC BCC EFC amongst other directories. I have already done a find to seek these 3 letter directories ...
3
votes
2answers
44k views

How to find and edit “Apache timeout”?

I'm trying to view the default value of Apache timeout of my server, but I found nothing about that in /etc/httpd/conf/httpd.conf . So where is " timeout " supposed to be and how do I change its value ...
0
votes
1answer
202 views

How do I extract specific URLs from an HTML file [duplicate]

I have an HTML file, without any formatting. I want to extract URLs of the form https://sitename.com/*/ending and only those URLs. What is the best way to go about doing this? This question is NOT a ...
4
votes
3answers
597 views

How to search efficiently for a list of strings in a big code directory

I have a list of strings, for every of those strings, I want to check if it occurs in a big source code directory. I came to a GNU grep solution that gives me what I want: for key in $(cat /tmp/...
1
vote
0answers
307 views

Search for occurrences of text in a long line in less

I am using less to view a file with many long lines. less automatically wraps these lines, but when I use / and n to search for something, it only shows the first occurrence of the text on a line. ...
2
votes
3answers
1k views

Find and rename files (including directories) whose filenames contain space [duplicate]

I have quite a number of files and directories with spaces in their filenames in my ext4 filesystems. How should I safely find and rename them? I have bash and am running Ubuntu. Is it possible ...
3
votes
2answers
219 views

How is it that the same find command can give two different results?

This has happened to me twice (EDIT: many times and I can replicate it) now. I'm working on a Raspberry Pi, looking for a file I already know exists and so I type this command: sudo find / -iname '...
1
vote
1answer
160 views

Search a string in files in the current directory, omit duplicates

Assuming I want to write a line which prints out lines which match a specific string without repeating duplicate lines .. I want to search for this string in the files of the current directory: grep ...
1
vote
3answers
501 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
0
votes
1answer
65 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
0
votes
2answers
50 views

search string in files and replace it incrementally

I have a directory with 152 files named plot_1 to plot_152. In each of those there's some R code with some index [[i]]. Using Kateversion 15.08.2, is it possible to search for [[i]] in each file and ...
1
vote
2answers
663 views

Mate menu (Linux Mint 17) searches files when pressing enter - can this be changed?

Example: I press Supper button: menu opens. I write "fir": it shows Firefox, just like any launcher. I press Enter, it starts searching the whole system for files named "fir". I can avoid this by ...
1
vote
2answers
87 views

How do I find a substring in a command line?

I have a few files that contains a similar entry like as follows: {"result":[]} {"result":[{"alternative":[{"transcript":"I win","confidence":0.87958056},{"transcript":"when"},{"transcript":"Schwinn"}...
3
votes
1answer
1k views

Regular Expression to match (not x) and y (!x & y)

I received a desktop day-to-day calendar with puzzles. One such puzzle was deciphering a quote where the letters were substituted with symbols. I used some RegExs to find longer words, then used the ...
3
votes
1answer
91 views

Why do less search result lines disappear/reappear?

When skimming through a file with less, I'm able to see all lines just fine. When I do a search and then go for the next result with n, sometimes a highlighted result is shown on the top line, and ...
0
votes
3answers
6k views

Search for a specific word in each line and print rest of the line

I have text file with server URL lines like: request get https://abc.net/search?q=hello/world/hello/word/search=5&size=10 request get https://abc.net/search?q=hello/world/hello/world/hello/word=5 ...
13
votes
3answers
3k views

Binary search in a sorted text file

I have a big sorted file with billions of lines of variable lengths. Given a new line I would like to know which byte number it would get if it had been included in the sorted file. Example a\n c\n ...
0
votes
1answer
1k views

New search in Mate desktop menu doesn't replace the previous one

In the Mate desktop it is easy to launch applications with the menu search (menu pops up with the default Super_L key). But it remembers the initial search in such a way that when I try to launch a ...
3
votes
1answer
1k views

grep search for any number in a range

So I have a file with a number of records that look like the following: Peugeot:206:2000:Red:1 And I'm trying to grep search for any that contain a year 1995-1999. I have tried grep '[1995-1999]' ...
3
votes
2answers
550 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 ...
-1
votes
1answer
165 views

How to write a Shell Script to find Inputs/Output of a Function in a given file

I need to write a shell script which tells us all function names in a given file and their inputs/outputs For Example consider the below file which has 2 functions. Each function has their input and ...