Multiline replace problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiline replace problem
# 1  
Old 02-13-2009
Multiline replace problem

I have a data of the form

0.0117843924 0. 0. 0. 0.
0.011036017 0. 0. 0. 0.
0.0103351669 0. 0. 0. 0.
4839.41211 0. 0. 0. 0.
4532.08203 0. 0. 0. 0.

I would like to insert a couple of blank lines before the 4839 line, every time it appears. The numbers in the first column follow the same pattern throughout the file, but the next 4 columns may change, so I can't just match the whole line.
Is there a neat way to do this, as I've had no luck with sed.
# 2  
Old 02-13-2009
Quote:
Originally Posted by mathis
...
I would like to insert a couple of blank lines before the 4839 line, ...
If I correctly understand you problem, one option would be:

Code:
awk '/^4839/{ for(i=1;i<=n;i++) printf RS; print; next }1' n=2 file

Change n to any number if you need more newlines.
# 3  
Old 02-13-2009
perfect
Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - How to update header of scripts in one pass - multiline search/replace

Hello. A find command return a list of file. For each fileReplace the content starting with the first "§" (of two) ending with last "ɸ" (of two), regardless of the content ( five lines ) by the following content (exactly) : §2019_08_23§ # # ... (8 Replies)
Discussion started by: jcdole
8 Replies

2. Shell Programming and Scripting

sed multiline problem

I'm trying to replicate the sed output on p.108 of Sed&Awk,by Doughery & Robbins, 2nd edition. I'm on a Windows 10 Surface Pro, running Cygwin for 64-bit versions of Windows. Input text saved in text file called data_p108.txt: Consult Section 3.1 in the Owner and Operator Guide for a... (9 Replies)
Discussion started by: prooney
9 Replies

3. UNIX for Dummies Questions & Answers

UNIX multiline replace

Hi We have a database export file which needs to be formatted as below InputCreate view ABC1 as Locking ABC1 for Access select * from PQR Create view ABC2 as Locking ABC2 for access select * from PQR Create view ABC3 as Locking ABC3 for Access select * from PQR OutputCreate... (5 Replies)
Discussion started by: sheetal.arun
5 Replies

4. Shell Programming and Scripting

How to replace word with multiline text using shell scripting.

Hi all I have data files which contain data as shown below: Line 5: FIDE INST_DESC: DIAM Co Ltd/Japan => MAID Co Ltd/Japan INST_NME: DIAM Co Ltd/Japan => MAID Co Ltd/Japan Line 6: FIDE INST_DESC: DIAM DL/Pimco US Bond Open Born in the USA => MAID DL/Pimco US Bond Open Born in the... (6 Replies)
Discussion started by: Ganesh_more
6 Replies

5. Shell Programming and Scripting

perl : replace multiline text between two marker points

Hi there I just wondered if someone could give me some perl advice I have a bunch of text files used for a wiki that have common headings such as ---++ Title blah ---++ Summary blah ---++ Details Here is the multiline block of text I wish to (6 Replies)
Discussion started by: rethink
6 Replies

6. Homework & Coursework Questions

VI Search and Replace problem help...

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Give the vi command for replacing all occurances of the string "DOS" with the string "UNIX" in the whole... (4 Replies)
Discussion started by: kbreitsprecher
4 Replies

7. UNIX for Advanced & Expert Users

Problem of Multiline in csv file

Hi I have csv file which has test as multiline in the one column. ex. ---------data.csv------------ Seqno,EmpID,EmpName,Dept 1,123,"Vipin Agrawal","IT BUSINESS OFFSHORE" 2,124,"Simon Bhai","IT" The problem is name "Vipin Agrawal" has one new line character b/w name. same as Dept. ... (1 Reply)
Discussion started by: meetvipin
1 Replies

8. Shell Programming and Scripting

problem with replace command with tr

I have a sample file like this 7829885 7831552 + 1 1667, 0, 35934936 35937087 - 2 1281,870, 0,1281, I would like to replace values starts with comma with just value like 0, to 0 or 1667, to 1667. I can do with this by using tr -d '0,' '0' <file But the... (2 Replies)
Discussion started by: repinementer
2 Replies

9. Shell Programming and Scripting

grep command to replace multiline text from httpd.conf file on Fedora

Hi, I am a newbie to shell scripting and to Linux environment as well. In my project I am trying to search for following text from the httpd.conf file <Directory '/somedir/someinnerdir'> AllowOverride All </Directory> and then remove this text and again rewrite the same text. The... (1 Reply)
Discussion started by: bhushan
1 Replies
Login or Register to Ask a Question