You will have to remove those if your input contains more than just the addresses. Note however that some of the expressions are used to match only the IP address and therefore contain beginning- ( ^) and end-of-line ( $) characters. You can find lots of IP address regular expressions on the web, see for example this StackOverflow question. grep -o 192.1.* zĪny line starting with 1921 will be matched, and only the matching part will be printed because of the -o switch.* matches anything up to the end of the line, including the empty string. Only 1921 will be matched, and only the matching part will be printed because of the -o switch. The first two are bang on the third is slightly off. Thirdly, it was written overnight to satisfy a particular need. Secondly, the wealth of options can be overwhelming. grep -i 'UNix' geekfile.txt Output: unix is great os. 01:13 The Story Behind grep The grep command is famous in Linux and Unix circles for three reasons. grep 'word' filename grep 'word' file1 file2 file3 grep 'string1 string2' filename cat otherfile grep 'something' command grep 'something' command option1 grep 'data' grep -color 'data' fileName How to use the grep command for searching in a file In the first example, I will search for the user 'tom' in the Linux passwd file. It matches the words like UNIX, Unix, unix. Your input does not contain data where this makes any difference. Case insensitive search : The -i option enables to search for a string case insensitively in the given file. will be matched, and only the matching part will be printed because of the -o switch. For example, if you want to look for a string in shell scripts only (files ending with. That could work, but a more practical example is to search into a particular type of files. Only 1921 will be matched, and only the matching part will be printed because of the -o switch. You may provide more than one file to grep to search into.
0 Comments
Leave a Reply. |