Yesterday a situation came up where someone needed me to separate out the tail end of a file, specified as being everything after a particular string (for sake of argument, "FOO"). I needed to do this immediately so went with the option that I knew would work and disregarded The Right Way or The Best Way, and went with the following:
grep -n FOO FILE.TXT | cut -f1 -d":" | xargs -I{} tail -n +{} FILE.TXT > NEWFILE.TXT
The thing that bugged me about this was the use of xargs for a singleton value. I thought that I could go flex my Google-Fu on this but was interested to see what sort of things people out in SO-land came up with for this situation
Search All Files in Directory To search all files in the current directory, use an asterisk instead of a filename at the end of a grep command. The output shows the name of the file with nix and returns the entire line.
Grep Command. grep is a built-in Linux command that prints lines that match a given pattern. It returns all the lines of a file that contain a certain string by default, and the command is also case-sensitive.
You can use grep with -A n option to print N lines after matching lines. Using -B n option you can print N lines before matching lines. Using -C n option you can print N lines before and after matching lines. Save this answer.
Search for a text string in a file & display all the lines where it is found. "string" The text string to find (must be in quotes). [pathname] A drive/file(s) to search (wildcards accepted). /V Display all lines NOT containing the specified string. /C Count the number of lines containing the string.
sed -n '/re/,$p' file
is what occurs to me right off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With