Here are some of the frequently used grep command in unix/Linux with examples:
1. Search a given string in a file
grep "search_string" file_name
2. Search a specific string in multiple files by providing the file name pattern
grep "search_string" file_name_pattern
e.g.: grep "name" class*.txt
3. Case insensitive search
grep -i "search_string" file_name
e.g.
Both commands would return same result
grep -i "name" class1.txt
grep -i "NAME" class1.txt
4. Invert match
grep -v "101" class1.txt
Above command would return all the rows that doesn't contain the string "101".
For latest technical interview questions, visit www.alldbest.com
1. Search a given string in a file
grep "search_string" file_name
2. Search a specific string in multiple files by providing the file name pattern
grep "search_string" file_name_pattern
e.g.: grep "name" class*.txt
3. Case insensitive search
grep -i "search_string" file_name
e.g.
Both commands would return same result
grep -i "name" class1.txt
grep -i "NAME" class1.txt
4. Invert match
grep -v "101" class1.txt
Above command would return all the rows that doesn't contain the string "101".
For latest technical interview questions, visit www.alldbest.com
No comments:
Post a Comment
Please give your feedback, questions and suggestions. I will surely answer you.