LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy from file1 to file2 - Trying sed (https://www.linuxquestions.org/questions/linux-newbie-8/copy-from-file1-to-file2-trying-sed-631291/)

LinuxCrayon 03-28-2008 11:38 AM

Copy from file1 to file2 - Trying sed
 
I'm learning to program in an environment without a GUI. During the course of my programming, I've found more and more that it would be better from an organization standpoint to move certain things from one file to another. At first, it was simple one or two line stuff that I could manually type out. Now, however, I'm trying to copy 78 lines of code, and that's just not going to work by hand. So I'm trying to use sed to do it for me. Right now, here's my code:

Code:

sed '1,78 p' file1 > file2
It works...in a sense. Except that for some weird reason, it copies the top portion 8 times, then the upper middle four times, lower middle 2 times, and the bottom part is copied correctly.

If there's a better way to copy only lines 1 through 78 from file1 to file2, I'd be interested in hearing it.

Thanks!

pixellany 03-28-2008 11:54 AM

SED prints everything unless told otherwise. In your example, it prints lines 1 thru 78 twice.

How about:
sed '79,$ d' file1 > file2

SED tutorial here:
http://www.grymoire.com/Unix/Sed.html

LinuxCrayon 03-28-2008 12:29 PM

Thanks, Pixellany. :)

i was able to accomplish everything I needed between your advice and that tutorial!

Tischbein 03-30-2008 07:51 AM

Quote:

Originally Posted by pixellany (Post 3103264)
SED prints everything unless told otherwise. In your example, it prints lines 1 thru 78 twice.

To print nothing unless explicitly commanded to, use the -n flag:

Code:

sed -n '5p'
Ha det.

Regards, Pute.


All times are GMT -5. The time now is 11:54 PM.