task_boiler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
task_boiler [2022/08/11 21:30] – [bare bones solution] raju | task_boiler [2024/01/23 22:55] (current) – raju | ||
---|---|---|---|
Line 3: | Line 3: | ||
Start the first heading with " | Start the first heading with " | ||
- | |||
- | ===== apply unix commands to all but the first line ===== | ||
- | ==== Situation ==== | ||
- | Let's say we want to sort a series of numbers in descending order but keep the header at the top. For example, given | ||
- | < | ||
- | $ echo -e " | ||
- | value | ||
- | 8 | ||
- | 2 | ||
- | 6 | ||
- | 3 | ||
- | </ | ||
- | we want to output | ||
- | < | ||
- | value | ||
- | 2 | ||
- | 3 | ||
- | 6 | ||
- | 8 | ||
- | </ | ||
- | |||
- | We can't directly use ' | ||
- | < | ||
- | $ echo -e " | ||
- | 2 | ||
- | 3 | ||
- | 6 | ||
- | 8 | ||
- | value | ||
- | </ | ||
- | |||
- | ==== Bare bones solution ==== | ||
- | Create a script called ' | ||
- | < | ||
- | # | ||
- | # | ||
- | # body: apply expression to all but the first line. | ||
- | # Use multiple times in case the header spans more than one line. | ||
- | # | ||
- | # Example usage: | ||
- | # $ echo -e " | ||
- | # | ||
- | IFS= read -r header | ||
- | printf ' | ||
- | " | ||
- | </ | ||
- | |||
- | Make it executable | ||
- | < | ||
- | chmod +x body | ||
- | </ | ||
- | |||
- | place it somewhere in your PATH (say ~/bin) | ||
- | < | ||
- | mv body ~/bin | ||
- | </ | ||
- | |||
- | This script will apply any unix command to all but the first line. For example, using it on our example | ||
- | |||
- | < | ||
- | $ echo -e " | ||
- | value | ||
- | 2 | ||
- | 3 | ||
- | 6 | ||
- | 8 | ||
- | </ | ||
- | |||
- | ==== practical solution ==== | ||
- | I got the above script from https:// | ||
task_boiler.txt · Last modified: 2024/01/23 22:55 by raju