How to display certain lines from a text file in Linux?

sed -n ‘10000000,10000020p’ filename You might be able to speed that up a little like this: sed -n ‘10000000,10000020p; 10000021q’ filename In those commands, the option -n causes sed to “suppress automatic printing of pattern space”. The p command “print[s] the current pattern space” and the q command “Immediately quit[s] the sed script without processing … Read more

sed fails with “unknown option to `s'” error

The problem is with slashes: your variable contains them and the final command will be something like sed “s/string/path/to/something/g”, containing way too many slashes. Since sed can take any char as delimiter (without having to declare the new delimiter), you can try using another one that doesn’t appear in your replacement string: Note that this … Read more

What is the difference between sed and awk?

sed is a stream editor. It works with streams of characters on a per-line basis. It has a primitive programming language that includes goto-style loops and simple conditionals (in addition to pattern matching and address matching). There are essentially only two “variables”: pattern space and hold space. Readability of scripts can be difficult. Mathematical operations are … Read more