Print Lines in a File From a Specific Line Number Until the End of the File with sed

If you know that you want all of the lines in a given file from n to EOF the following is the sed command:

sed -n '3,$p' some_file.txt

To print out lines 2 – 5 simply modify it to:

sed -n '2,5p' some_file.txt

Continue reading “Print Lines in a File From a Specific Line Number Until the End of the File with sed”

Removing the Last Token From a String in Bash with awk

Let’s say that you have some number of files for which you want to create a containing directory that is named with all but the last token of the file name, and you want to remove just the last token to create the name of the directory.

Much easier to explain with an example.  Given this list of files:

ls -1
foo_10_10_sometrash
foo_1_sometrash
foo_2_sometrash
foo_3_sometrash
foo_4_sometrash
foo_5_5_sometrash
foo_5_sometrash
foo_6_6_sometrash
foo_7_7_sometrash
foo_8_8_sometrash
foo_9_9_sometrash

You want to create a directory for each → Continue reading “Removing the Last Token From a String in Bash with awk”