LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-17-2011, 03:36 AM   #1
velgasius
LQ Newbie
 
Registered: Oct 2011
Posts: 7

Rep: Reputation: Disabled
Bash command to 'cut' text into another text file & modifying text.


I have a text file named fruitsIlike.txt containing these lines:

I like Apples
I like Oranges
I like Grapes
I like Kiwis
I like Pie

What I want to do is to cut 1 or 2 lines and move it to another text file named movedhere.txt

and how do I modify say..."I like Kiwis" to "I don't like Kiwis"??
I was thinking the theory might be moving all lines before "I like Kiwis" and after it to 2 separate files, then deleting "I like Kiwis" and moving back the 1st batch of text to that file, echoing "I don't like Kiwis" and then moving back the 2nd batch of text.

or is there an easy way?lol
 
Old 10-17-2011, 04:11 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,489

Rep: Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891
Investigate tools like sed or awk or alternatively use a bash script to read through file and output as necessary.
 
Old 10-17-2011, 04:17 AM   #3
velgasius
LQ Newbie
 
Registered: Oct 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
well the problem is I rly dont understand anything other than the basics, I googled sed and awk and it seems too complicated to me, mind explaining it in a noob languange?>_< along with the codes if possible
 
Old 10-17-2011, 04:44 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,489

Rep: Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891Reputation: 1891
Example of delete can be found here using sed

If you look further through the whole page you should find solutions to each part of your question.
 
Old 10-17-2011, 04:55 AM   #5
velgasius
LQ Newbie
 
Registered: Oct 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
wow thanks!that looks like an ocean of info lol xD
 
  


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
Get data from multi lined text file using awk, sed or perl - grep & cut not upto par cam34 Programming 4 07-02-2010 03:10 AM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-10-2008 11:13 PM
what is the command to add text into a text file? newbiebash Programming 2 09-08-2008 08:07 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM


All times are GMT -5. The time now is 05:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration