apply_unix_commands_to_all_but_the_first_line
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
apply_unix_commands_to_all_but_the_first_line [2022/08/11 22:00] – created raju | apply_unix_commands_to_all_but_the_first_line [2022/08/12 16:44] – [How I came across it] raju | ||
---|---|---|---|
Line 69: | Line 69: | ||
I got the above script from https:// | I got the above script from https:// | ||
- | A more practical approach is to clone that entire repository and add it to your PATH. | + | A more practical approach is to clone that entire repository and add it to the shell' |
I did it as follows. | I did it as follows. | ||
- | Remove the bare bones script | + | Remove the bare bones script added in the previous step |
< | < | ||
% rm ~/bin/body | % rm ~/bin/body | ||
Line 101: | Line 101: | ||
</ | </ | ||
- | Open a new bash session and verify that these utilities | + | Open a new bash session and verify that the scripts |
< | < | ||
% which body | % which body | ||
Line 110: | Line 110: | ||
</ | </ | ||
- | Verify that the utilities | + | Verify that the scripts |
< | < | ||
% 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.txt · Last modified: 2022/08/12 17:29 by raju