LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-29-2012, 09:45 PM   #1
sritri
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Rep: Reputation: Disabled
Line manipulation


Hi,

I need some help for file manipulation. I have a text file 150k lines long like below:
RHR
DVH001Test1
DVR001
DVR002
DVR001
DVR002
DVR001
DVR002
DVR001
DVR002
CGH001Test2
CGR001
CGR002
CGR001
CGR002
CGH001
CGR001
CGR002
DVH001Test3
DVR001
DVR002
DVR001
DVR002

I need to read this file line by line and then insert the DVH/CGH line after every DVR002/CGR002 line. So the above should be :

RHR
DVH001Test1
DVR001
DVR002
DVH001Test1
DVR001
DVR002
DVH001Test1
DVR001
DVR002
DVH001Test1
DVR001
DVR002
CGH001Test2
CGR001
CGR002
CGH001Test2
CGR001
CGR002
CGH001Test2
CGR001
CGR002
DVH001Test3
DVR001
DVR002
DVH001Test3
DVR001
DVR002
RTR

Thank for your time and help

Shreeni
 
Old 12-30-2012, 01:33 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

Please share with us what you have done so far.
 
Old 12-30-2012, 03:30 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Hi and welcome to LQ.

1. See the post above
2. I think you need to define your problem in clearer way because IMHO your definition and sample output are not consistent.
3. Have a look at SED's "a" command.
http://www.grymoire.com/Unix/Sed.html#uh-40
 
Old 01-03-2013, 08:45 AM   #4
sritri
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
I got the problem solved with a bit Python code to simulate a control-break

Thank you all.
 
  


Reply



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
[SOLVED] A question about file manipulation from the command-line marcusrex Linux - Newbie 4 03-23-2012 11:07 AM
LXer: Flimp - Graphical frontend for Command Line Image Manipulation tools LXer Syndicated Linux News 0 10-15-2008 07:00 AM
text manipulation, REGEX plus the following line farkus888 Solaris / OpenSolaris 3 02-27-2007 06:26 PM
command line image manipulation (imagemagick?) exodist Linux - Software 3 03-13-2006 01:35 PM
Hardware Manipulation From Command Line LouisTheDamned Linux - Newbie 2 03-27-2004 03:42 PM

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

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

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
Open Source Consulting | Domain Registration