Copy lines from x to y to another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy lines from x to y to another file
# 8  
Old 05-30-2018
Hi Rudic,
I didn't quite get the post ( -n, --lines=[+]NUM ) on asking me to refer the manpage of tail command.
# 9  
Old 05-30-2018
It principally reads: if tail +2 doesn't work for you (it does on my computer), try tail -n+2. Generally: check the man page for your tool & version to find out what it provides and what it misses.


Shortest possible solution:
Code:
sed '2,6!d' file

This User Gave Thanks to RudiC For This Post:
# 10  
Old 05-31-2018
Quote:
Originally Posted by RudiC
It principally reads: if tail +2 doesn't work for you (it does on my computer), try tail -n+2.
I would write tail -n +2(with space). I think this is the "most canonical" form. On very old Unixes, the first variants of head and tail did not provide the -n switch. Then, for some time, I found it supported on several platforms, but marked as obsolete, and -n was favoured. Hence, even if the old form would still work, I would prefer using an explicit -n, simply for compatibility.
These 2 Users Gave Thanks to rovf For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy only some lines from very big file?

Dear all, I have stuck with this problem for some days. I have a very big file, this file can not open by vi command. There are 200 loops in this file, in each loop will have one line like this: GWA quasiparticle energy with Z factor (eV) And I need 98 lines next after this line. Is... (6 Replies)
Discussion started by: phamnu
6 Replies

2. Shell Programming and Scripting

How to copy lines that starts with either 3 or 4 into new file?

Hi Guys, I have an awk script that would search the input file for line that starts with a number 3 and copies into a new text file. I want to extend this script to find the lines that either starts with 3 or a or b and copy all those lines into the new file. Here is what I have so far:... (1 Reply)
Discussion started by: Amith821
1 Replies

3. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

4. Shell Programming and Scripting

Copy selective lines from text file

Hello, I have a text file which I need to check for presence of certain tags, and then copy a subsequent portion of text into another file. The tag matching canbe done with Grep but I do not know how to copy selective lines from one file to another. Is it possible do that? I checked up some... (8 Replies)
Discussion started by: ajayram
8 Replies

5. UNIX for Dummies Questions & Answers

copy and paste certain many lines of huge file in linux

Dear All, I am working with windoes OS but remote a linux machine. I wonder the way to copy an paste some part of a huge file in linux machine. the contain of file like as follow: ... dump annealling all custom 10 anneal_*.dat id type x y z q timestep 0.02 run 200000 Memory... (2 Replies)
Discussion started by: ariesto
2 Replies

6. Shell Programming and Scripting

Grep: Copy all lines from log file into new file

Hello everyone. I have a log file that contains multiple domains: www.thisdomain.com agent.thisdomain.com that.thisdomain.com I need to copy all of the lines that contain "www.thisdomain.com" from the log and output them into a new file. I've tried everything with little luck. Please help... (3 Replies)
Discussion started by: aberli
3 Replies

7. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies

8. UNIX for Dummies Questions & Answers

copy lines from opne file to another

Hi all, I'm new to shell scripting. I want to copy the first N lines from a file to another file. Can someone please tell me how this can be done. Thanks Himi (2 Replies)
Discussion started by: HIMANI
2 Replies

9. Shell Programming and Scripting

How to copy multiple lines from a file to another using AWK?

Hi, I have a abc.txt file. In this file there is a SQL query which Iwant to copy and print it on another file.The query (for eg) is written like this: SELECT field1, field2, field3 from table1,table2 where <conditions> END I want to copy this query to another... (3 Replies)
Discussion started by: jisha
3 Replies

10. Shell Programming and Scripting

Copy only the initial 10 lines from a file to another

Hi all, I'm new to shell scripting. I want to copy initial few lines(say first 10 lines) from a file to another file. There is no "head" command in our embedded system. sed & awk is there which I believe will do that, but I dont know how to. This is linux 2.6 (embedded) So please help me.... (5 Replies)
Discussion started by: jockey007
5 Replies
Login or Register to Ask a Question