How to search in linux for a portuguese character - search

Can i use Grep/ any other tool to search recursively for a Portuguese string recursively inside a linux folder ? Word to search is : Observaçãosobreretiradadebrind
i have tried
grep -inr "Observaçãosobreretiradadebrind"
That doesnt work. Any pointers/Help ??

It seem that -P (perl-regexp) works:
grep -P "Observaçãosobreretiradadebrind" file
Observaçãosobreretiradadebrind

Related

How to replace a string in multiple files in multiple subfolders with different file extensions in linux using command line

I have already followed this query # (How to replace a string in multiple files in linux command line).
My question is rather an extension of the same.
I want to check only specific file extensions in the subfolders also but not every file extension.
What I have already tried:
grep -rli 'old-word' * | xargs -i# sed -i 's/old-word/new-word/g' #
My problem: It is changing in every other file format as well. I want to search and replace only in one file extension.
Please add another answer where I can change the entire line of a file as well not just one word.
Thanks in advance.
Simplest solution is to use complex grep command:
grep -rli --include="*.html" --include=".json" 'old-word' *
The disadvantage of this solution. Is that you do not have clear control which files are scanned.
Better suggesting to tune a find command to locate your desired files.
Using RegExp filtering option -regex to filter file names.
So you verify the correct files are scanned.
Than feed the find command result to grep scanning list.
Example:
Assuming you are looking for file extensions txt pdf html .
Assuming your search path begins in /home/user/data
find /home/user/data -regex ".*\.\(html\|txt\|pdf\)$"
Once you have located your files. It is possible to grep match each file from the the above find command:
grep -rli 'old-word' $( find /home/user/data -regex ".*\.\(html\|txt\|pdf\)$" )

How to find a file containing specific text in Centos7?

I have a server which runs on centos 7. I need to find a file containing 0774386850 so that I can replace with another string. Kindly give me a Linux command to give me that file
By using grep command, you can achieve what you expected
grep -rlnw '/path/to/somewhere/' -e '0774386850'
-r or -R is recursive,
-n is line number, and
-w stands for match the whole word.
-l (lower-case L) file name of matching files.
grep -r "0774386850 " /path/to/dir
You can use either grep/fgrep or find to achieve your goal.

Linux Command to search for text in particular file

I need a little help. Basically, I am trying to search a text string in wordpress theme files.
That string is located in wp-content/themes/style.css.
So basically I am trying to search a string in all style.css files on all wordpress installations of home directory.
Is it possible to search all style.css files only and if the string is found display it?
Thanks in advance!
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c
Use grep to search for text inside files.
grep -rniw '/path/to/somewhere/' -e 'pattern'
-r or -R is recursive,
-n is line number, and
-i - case insensitive search
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.
For you case, use:
grep -rniw '/path/to/somewhere/' -e 'wp-content/themes/style.css'
Use the following commands:
cd /home/
find . -iname "*.css" -exec grep -l "text_string" {} +
Do not forget to replace text_string with the actual text string.

Finding multiple strings in directory using linux commends

If I have two strings, for example "class" and "btn", what is the linux command that would allow me to search for these two strings in the entire directory.
To be more specific, lets say I have directory that contains few folders with bunch of .php files. My goal is to be able to search throughout those .php files so that it prints out only files that contain "class" and "btn" in one line. Hopefully this clarifies things better.
Thanks,
I normally use the following to search for strings inside my source codes. It searches for string and shows the exact line number where that text appears. Very helpful for searching string in source code files. You can always pipes the output to another grep and filter outputs.
grep -rn "text_to_search" directory_name/
example:
$ grep -rn "angular" menuapp
$ grep -rn "angular" menuapp | grep some_other_string
output would be:
menuapp/public/javascripts/angular.min.js:251://# sourceMappingURL=angular.min.js.map
menuapp/public/javascripts/app.js:1:var app = angular.module("menuApp", []);
grep -r /path/to/directory 'class|btn'
grep is used to search a string in a file. With the -r flag, it searches recursively all files in a directory.
Or, alternatively using the find command to "identify" the files to be searched instead of using grep in recursive mode:
find /path/to/your/directory -type f -exec grep "text_to_search" {} \+;

Terminal command to find lines containing a specific word?

I was just wondering what command i need to put into the terminal to read a text file, eliminate all lines that do not contain a certain keyword, and then print those lines onto a new file. for example, the keyword is "system". I want to be able to print all lines that contain system onto a new separate file. Thanks
grep is your friend.
For example, you can do:
grep system <filename> > systemlines.out
man grep and you can get additional useful info as well (ex: line numbers, 1+ lines prior, 1+lines after, negation - ie: all lines that do not contain grep, etc...)
If you are running Windows, you can either install cygwin or you can find a win32 binary for grep as well.
grep '\<system\>'
Will search for lines that contain the word system, and not system as a substring.
below grep command will solve ur problem
grep -i yourword filename1 > filename2
with -i for case insensitiveness
without -i for case sensitiveness
to learn how grep works on ur server ,refer to man page on ur server by the following command
man grep
grep "system" filename > new-filename
You might want to make it a bit cleverer to not include lines with words like "dysystemic", but it's a good place to start.

Resources