Help in replacing two blank lines with two lines of diff data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in replacing two blank lines with two lines of diff data
# 1  
Old 12-02-2011
Help in replacing two blank lines with two lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script...
I used sed to search a line and insert two blank lines after the searchd line using the following sed command.
sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines.. Now i'm trying to insert 2 different data into the same blank lines.. But cudn't get the command for that... Any help wud b appreciated...

Thanks in advance..

Last edited by Scott; 12-02-2011 at 06:05 AM.. Reason: Code tags
# 2  
Old 12-02-2011
I think this is the continuation of the below question. Can I know y u created new thread and what u did to insert new lines??

https://www.unix.com/shell-programmin...-new-line.html
# 3  
Old 12-02-2011
I used :
Code:
sed  "/<data>/{G;G;}/" fileName>tempFile

to create two blank lines after searching for the tag <data>.... After creating blank lines I tried to replace them with two different data, but couldn't get the result.... sed could be used to make a single change to many lines only..

Last edited by Scott; 12-02-2011 at 06:05 AM.. Reason: Please use code tags
# 4  
Old 12-02-2011
Where are these two lines of "data" coming from?

(siva shankar, as the question is the opposite of what was asked before, it can't be a continuation of the mentioned thread, IMO)
# 5  
Old 12-03-2011
Its coming from a flat file and it will be choosed depending upon the value of <data> in the sed command.
after inserting the statements, the results would be like:

<modulename>$data1</modulename>
<submodulename>$data2</submodulename>

where $data1 and $data2 will be taken dynamically from another flat file using a loop.
These are two lines of data which i need to add...

---------- Post updated at 04:02 PM ---------- Previous update was at 03:41 PM ----------

I tried to use s/text1/text2/g... but here the blank lines are getting replaced by the same piece of line... Smilie

---------- Post updated 12-03-11 at 09:48 AM ---------- Previous update was 12-02-11 at 04:02 PM ----------

Can we use two different sed to replace the first occurrence of blank statements with data?
I tried using sed -e 's/^$/mydata/' filename... but this command replaced both the blank statements with my data... is there any other option to replace the first occurrence of blank statement with my data?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete multiple lines between blank lines containing two patterns

Hi all, I'm looking for a way (sed or awk) to delete multiple lines between blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies

2. Shell Programming and Scripting

Reform Lines in File without blank lines and spaces

Hello All, I have a file with data as below. Each line consists of 21 fields. I am not able to load them back to the database. 50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Data Element Miss ing... (3 Replies)
Discussion started by: Praveenkulkarni
3 Replies

3. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

4. Shell Programming and Scripting

Text file to CSV with field data separated by blank lines

Hello, I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies

5. Shell Programming and Scripting

sed show lines text between 2 blank lines

I have a file like blah blah blah blah this is the text I need, which might be between 1-4 lines, but always has a blank line above and below it, and is at the end of the text file the code tags don't show the trailing blank line. I started by deleting the last blank line with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shell Programming and Scripting

Help in replacing two blank lines with two diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. Sed "/data/{G;G;}/" filename. In the file, after data tag, two lines got inserted blank lines.. Now... (1 Reply)
Discussion started by: arjun_arippa
1 Replies

7. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

8. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

9. Shell Programming and Scripting

replacing blank lines

Hi i am trying to replace blank lines with a number 0. I tried the following code awk '{print NF ? $0: blankrow}' blankrow = "0" file1.prg>file2.prg however i get the following error: fatal: cannot open file `blankrow' for reading (No such file or directory) file example: 1 2 3 5 6... (11 Replies)
Discussion started by: rockiefx
11 Replies

10. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies
Login or Register to Ask a Question