We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Middle of a Text File
Middle of a Text File
+ 3 comments Or use
+
prefix to start counting from the begining:head -n 22 | tail -n +12
+ 1 comment I could come up with 3 solutions for this. Since most of us are in a learning phase, this may help in broadening the understanding of the language-
- Remember "cut" for previous questions? You can change the delimiter to '\n', meaning that each field would now correspond to a line.
cut -d$'\n' -f12-22
- Just like head, tail command exists which can print the last n lines of a file. So just pass the first 22 lines from head to tail via a pipe.
head -n 22 | tail -n 11
- I actually came up with this solution first since I didn't know about tail. Basically, take the first 22 lines (from head) and pass then to a counter which will ignore the first 11 lines and start printing from the 12th.
count=1 head -n 22 | while read line; do if [ $count -ge 12 ]; then echo $line; fi; count=$(($count+1)); done
Hope it helps!
+ 2 comments head -22 | tail -11
I think this is the simplest way to do it.
+ 1 comment sed -n '12,22p'
+ 2 comments I found a simple solution using the sed command but I don't know if I can use it to solve this problem. Other approaches to find a solution consist in use both commands, head and tail, passing the output of the first command as input of the second command.
Load more conversations
Sort 81 Discussions, By:
Please Login in order to post a comment