Shell: Day #4
Today was the day with the commands grep and sed.
grep – command used for the patter matching it have many useful options
- -i: to make case-insensitive search
- -r: search through the file in dire recursively
- – l: print the name of the file with matching string
- -c: print the counts of match
- -n: numbers the matching lines in the output
- -v: it's like not condition, print the reverse of the condition
sed – its read the input lines, run script on them, and writes them to stdout. This command is good for the string replacement and editing of the files.
Both these commands can be used with regex for the pattern matching.
>> grep -nv ^# \| ^$ /etc/services |less
# will list all the lines from the file with do not start with *#* and ends with an empty line.
>>sed ``s/UNIX/LINUX` file.txt
# sed command will replace the occurrence of the *UNIX* word with the *LINUX*