How do I get all files with .md extension, in all subdirectories, that contain a phrase? [duplicate] - linux

This question already has answers here:
Linux search text string from .bz2 files recursively in subdirectories
(4 answers)
Closed 6 months ago.
I have a parent folder named 'dev', and inside it are all my project folders. The ReadMe files of these projects contain the app type "type: game", for example. What I would like to do is to:
search through all subdirectories of the dev folder to find all the files with *.md" extension
then return the names of those directories which contain a .md files with containing the phrase "game"
I've tried piping find into grep like so:
find -type f -name "*.md" | grep -ril "type: game"
But it just returns the names of files from all subdirectories which contain the phrase "game" in any file.

find . -type f -name "*.md" -print0 | xargs -0 grep -il "type: game" | sed -e 's/[^\/]*$//'
This finds any files in the current directory and sub-directories with names ending with .md, then greps for files containing the string. We then use sed to trim the filename leaving only the directories containing a file ending in .md with the "type: game" inside.

Related

To get only the regular files and directories but not the hidden files and directories

find -type f | grep -ril 'String' ~
/home/ankit/.bash_history
/home/ankit/.filename.swo
/home/ankit/.filename.swp
/home/ankit/.perl_Eg.pl.swp
/home/ankit/.sample.swl
/home/ankit/.sample.swm
/home/ankit/.sample.swn
/home/ankit/.sample.swo
/home/ankit/.sample.swp
/home/ankit/.viminfo
/home/ankit/ankitrai
/home/ankit/array.sh
/home/ankit/array2.sh
/home/ankit/d1/text.txt
/home/ankit/direct/space
/home/ankit/filename
/home/ankit/function1.sh
/home/ankit/mail.pl
/home/ankit/perl_Eg.pl
/home/ankit/test.sh
/home/ankit/tmp
i'm using the above command to search a file with the string but it was giving the hidden files also,i dont need the hidden files and directories.

How can I search for specific file contents in all files in both current folder and all subfolders [duplicate]

This question already has answers here:
How do I recursively grep all directories and subdirectories?
(26 answers)
Closed 4 years ago.
Using Mac terminal server linux/bash commands, how can I search for a particular text string in all *.txt files in the current folder plus all files in the subfolders inside the current folder?
grep -i "xxx" */*
xxx is the target text I am trying to find.
find . -type f -print | egrep ".txt$" | xargs grep "SearchPatern"
Explained as
Find all the file names in the current directory and below send to ....
grep which picks out the file name that end in .txt and send names to ....
xargs which will execute a grep command on each file to look for SearchPatern.

How to search for text files containing a text string on a linux system

I want to collect and move all text files that contain the string “MEDIUM” that are present in my subdirectories on a linux system, to a new folder called MEDIUM_files. I am able to collect all files containing MEDIUM by using
ls *MEDIUM*
but I only want the text files.
All the files contain MEDIUM, but they also differ in number. For example the file name contain different numbers at the end such as "MEDIUM_30_1.txt" or through "MEDIUM_1850_20.txt"
How can I specify a file type as well as containing a string?
find . -type f | grep MEDIUM | grep '\.txt$' | xargs -I{} mv {} MEDIUM_files

how to list full paths of folders inside a directory in linux? [duplicate]

This question already has answers here:
Show full path when using options
(8 answers)
Closed 8 years ago.
I have a folder /home/Documents/myFolder and inside this folder there are lots other folders. I want to have a file list.txt which contains all the paths of the folders. I want the text file content like this:
/home/Documents/myFolder/1234
/home/Documents/myFolder/asd2
/home/Documents/myFolder/asdawgf
/home/Documents/myFolder/dawt
.
.
.
I tried this one but it was not what I want ls > /home/Documents/myFolde/list.txt
it just prints the folder names. I want the full paths.
Use find listing all directories (-type d) and then sed the output to get the full path correct:
find . -type d | sed -n 's:^\./:/home/Documents/myFolder/:'p > /home/Documents/myFolder/list.txt
you can use find:
find . > /home/Documents/myFolde/list.txt

linux command to concatenate multiple files with content separated by filenames?

I am looking for a command that will concatenate multiple files in a directory tree with sames having a pattern such that the resulting file has contents of all the files separated by the name(path) of each file. I tried using find -exec and sed but couldn't succeed.Please help.
More specifically I have a directory containing many sub-directories having file named 'test.FAILED'. I want to concatenate all the test.FAILED files separated by their Paths so that I can have a look at all of them at the same time.
for i in <pattern>
do
echo "$i"
cat "$i"
done > output
Using (gnu) find:
find . -name \*.FAILED -print -exec cat "{}" \;

Resources