apply_unix_commands_to_all_but_the_first_line
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
apply_unix_commands_to_all_but_the_first_line [2022/08/12 13:39] – [Practical solution] raju | apply_unix_commands_to_all_but_the_first_line [2022/08/12 17:29] (current) – [Situation] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Apply unix commands to all but the first line ===== | ===== Apply unix commands to all but the first line ===== | ||
==== Situation ==== | ==== Situation ==== | ||
- | Let's say we want to sort a series of numbers in descending | + | Let's say we want to sort a series of numbers in ascending |
< | < | ||
% echo -e " | % echo -e " | ||
Line 129: | Line 129: | ||
==== How I came across it ==== | ==== How I came across it ==== | ||
- | I came across it while reading | + | The ' |
+ | |||
+ | ==== Close but no cigar ==== | ||
+ | Here I will try to list some alternative approaches that are close but not perfect. | ||
+ | |||
+ | Solution 1: | ||
+ | < | ||
+ | $ cat input.txt | ||
+ | value | ||
+ | 8 | ||
+ | 2 | ||
+ | 6 | ||
+ | 3 | ||
+ | |||
+ | $ (head -n 1 input.txt; tail -n +2 input.txt | sort) | ||
+ | value | ||
+ | 2 | ||
+ | 3 | ||
+ | 6 | ||
+ | 8 | ||
+ | </ | ||
+ | |||
+ | Disadvantages: | ||
+ | * Requires two passes on the input (once to extract the header and another to process the body) | ||
+ | * Does not work if the input is coming from stdin | ||
apply_unix_commands_to_all_but_the_first_line.1660311550.txt.gz · Last modified: 2022/08/12 13:39 by raju