LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2009, 04:08 PM   #1
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Rep: Reputation: 0
deleting lines from text files


Is there anyway to delete certain paragraphs within a text file and then insert the paragraph into another text file.

I just cannot figure out how to remove the specific lines from the file and then insert them into another file at a certain line within that new file. Thanks again
 
Old 09-17-2009, 04:11 PM   #2
j_jerry
Member
 
Registered: Sep 2009
Distribution: fedora 11
Posts: 318

Rep: Reputation: 46
You want to do this in terminal ?
 
Old 09-17-2009, 04:31 PM   #3
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Yes if at all possible
 
Old 09-17-2009, 04:31 PM   #4
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Original Poster
Rep: Reputation: 0
I was thinking either the mv command or join command would be possible but im not sure.
 
Old 09-17-2009, 04:36 PM   #5
j_jerry
Member
 
Registered: Sep 2009
Distribution: fedora 11
Posts: 318

Rep: Reputation: 46
mv is for moving files

btw, its not easy at all. Why can't you do it in X ?
 
Old 09-17-2009, 04:40 PM   #6
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Original Poster
Rep: Reputation: 0
How can I do it in X
Sorry im just learning about all this
 
Old 09-17-2009, 04:44 PM   #7
compgenius999
Member
 
Registered: Aug 2009
Location: England
Distribution: Fedora 13
Posts: 73

Rep: Reputation: 15
You use something like gedit which is a graphical text editor, although in the terminal you could use something like nano which is a terminal text editor with a GUI
 
Old 09-17-2009, 05:34 PM   #8
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
Code:
$ nano file1
    scroll down and highlight text
    Cut to remove text from file1
    ctrl i and enter and X
$ nano file2
     Scroll down to point of insert
     Dont remember the paste command
     Save and exit as above
Would do what you want to do but you need to experiment with the cut save and paste commands
 
Old 09-17-2009, 05:36 PM   #9
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by caponewgp View Post
Is there anyway to delete certain paragraphs within a text file and then insert the paragraph into another text file.

I just cannot figure out how to remove the specific lines from the file and then insert them into another file at a certain line within that new file. Thanks again
If this is homework, please say so. I ask because people for whom this is not homework know how to do this.

Here is pseudo-code to accomplish the goal:

1. Create two new empty files, REJECT and ACCEPT.

2. Read lines from the DATA file and test for the presence of certain text patterns.

3. For lines that contain the desired pattern, copy them into ACCEPT.

4. For lines that do not contain the desired pattern, copy them into REJECT.

5. When the DATA file has been completely read, copy file REJECT over file DATA.

6. Done.
 
Old 09-17-2009, 07:39 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
If you want to do this from the cmd line, potentially scripted, you can use the head & tail cmds to do the extract.
I believe sed can do inserts at specified line nums.
You could even use head & tail to split the target file then concat (cat) the pieces back together for the insert.
 
Old 09-17-2009, 10:47 PM   #11
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
Copy text from one file to another using Vim

I'm assuming you want to copy text without writing a program.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Interlacing the lines of two text files khdubya Programming 3 02-03-2007 06:27 PM
deleting specified lines in a huge text file ruh31 Linux - General 10 06-30-2006 04:34 AM
reverse order some lines of text files Melsync Programming 4 09-20-2005 05:40 PM
An easy way of deleting lines from multipe files? delawhere Linux - General 2 04-02-2004 12:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration