'Merge sed commands into a script
I need to write these two sed commands in a single script.
sed -n '10,20p' file.txt | sed '1!G;h;$!d'
I selects lines in range from 10 to 20 and prints them in a reverse order Could anybody please help me with this?
Solution 1:[1]
This seems to be working
#!/bin/sed -Ef
10!G
h
20!d
Solution 2:[2]
If sed is still your most preferable tool then:
$ seq 20 | sed -n '10,15{10!G;h;15p}'
15
14
13
12
11
10
However, I don't like that line numbers (10 & 15) needs to be specified twice. sed -n '10,20p' file.txt | tac seems better...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CrashCZ |
| Solution 2 | Jarek |
