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 12-29-2012, 10: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, 02:33 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 286

Rep: Reputation: 61
Hi,

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

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
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, 09: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


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


All times are GMT -5. The time now is 08:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration