Grep Command GREP -- stands for Global Regular Expression Parser searching for a word in a file grep 200 filename example I am searching for string "ravana" in the file $ grep ravana data.txt Ravana 9309080497 ravana@gmail.com Newzealand Ravana 9309080497 ravana@gmail.com Newzealand You can also use "" to look for the content $ grep "ravana" data.txt Ravana 9309080497 ravana@gmail.com Newzealand Ravana 9309080497 ravana@gmail.com Newzealand Ravana 9309080497 ravana@gmail.com Newzealand Searching data in more than one file. grep "john" filename1 filename2 $ grep "ravana" data.txt info.txt data.txt:R...
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AWK AWK stands for "Aho, Weinberger, and Kernighan". It is named after its creators Alfred Aho, Peter Weinberger, and Brian Kernighan, who developed the language while working at Bell Labs in the 1970s. replace a word with another word awk '{gsub(/sreejith/, "Balakrishnan"); print}' filename // This will replace all the sreejith to Balakrishnan Print a particular word if that appears in the file awk '{for(i=1;i<=NF;i++) if ($i == "word") print $0}' filename Print only once if a word was found in the file awk '{for (i=1; i<=NF; i++) if ($i == "sreejith" && !seen[$i]++) print $i}' test-file.txt Print the last word that has "america" as its last word awk '$NF ~ /america$/' test-file.txt or awk '$NF ~ /america$/{print $0}' test-...
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SED (Stream Editor) is a powerful command-line utility in Linux used for performing various text manipulation tasks such as search and replace, filtering, and transformation. Here are some commonly used SED commands in Linux: cat -n filename // displays output using line numbers Print a particular line multiple time. sed '2p' filename // This print 2nd lines along with other but 2nd line printed twice sed -n '16p' data.txt // This print the 16th line alone $ sed -n '3{p;p;p}' data.txt Sreejith 7898980090 sreejith.sbk@gmail.com London Sreejith 7898980090 sreejith.sbk@gmail.com London Sreejith 7898980090 sreejith.sbk@gmail.com London $ for ((i=...
Comments
Post a Comment