replace string with a newline string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replace string with a newline string
# 1  
Old 05-29-2009
replace string with a newline string

Hi,

I wanted to replace these lines in vi editor:

input--


uid=ESVPEME | eriMasterDomain=EAMCS | eriCountry=El | ou=ESV
uid=EPYCAR | eriMasterDomain=EAMCS | eriCountry=Argentina | ou=CEA
uid=ERCFGA | eriMasterDomain=EAMCS | eriCountry=Costa | ou=ERC
uid=EDGLUCU | eriMasterDomain=EAMCS | eriCountry=Guatemala | ou=EDG
uid=TIMRZOR | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=CEVPAAR | eriMasterDomain=EAMCS | eriCountry=Venezuela | ou=CEV
uid=QLUIFRA | eriCountry=Mexico | ou=TAM | uid=EUSIAJ | eriMasterDomain=EAMCS | eriCountry=United | ou=EUS
uid=TIMHUHA | eriCountry=Mexico | ou=TAM | uid=TIMCGRR | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=TIMMME | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=CCUAZU | eriMasterDomain=EAMCS | eriCountry=Argentina | ou=CEA
===========================

out put sholul look like this====>


uid=ESVPEME | eriMasterDomain=EAMCS | eriCountry=El | ou=ESV
uid=EPYCAR | eriMasterDomain=EAMCS | eriCountry=Argentina | ou=CEA
uid=ERCFGA | eriMasterDomain=EAMCS | eriCountry=Costa | ou=ERC
uid=EDGLUCU | eriMasterDomain=EAMCS | eriCountry=Guatemala | ou=EDG
uid=TIMRZOR | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=CEVPAAR | eriMasterDomain=EAMCS | eriCountry=Venezuela | ou=CEV
uid=QLUIFRA | eriCountry=Mexico | ou=TAM
uid=EUSIAJ | eriMasterDomain=EAMCS | eriCountry=United | ou=EUS
uid=TIMHUHA | eriCountry=Mexico | ou=TAM
uid=TIMCGRR | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=TIMMME | eriMasterDomain=EAMCS | eriCountry=Mexico | ou=TAM
uid=CCUAZU | eriMasterDomain=EAMCS | eriCountry=Argentina | ou=CEA

=============================

every "uid" will come in next line...

how can I proceed??
thanks in advance
# 2  
Old 05-29-2009
Try...
Code:
:%s/ uid/Ctrl-VCtrl-Muid//

# 3  
Old 05-29-2009
is it possible to use sed??
# 4  
Old 05-29-2009
Quote:
Originally Posted by hegdeshashi
is it possible to use sed??
Type <Ctrl>-V <Enter> for the ^M:

Code:
sed s'/ | uid/^Muid/' file > newfile

# 5  
Old 06-01-2009
Hi,

sed s'/ | uid/^Muid/' file > newfile ===> is not giving the output as my requirment..

If the input file contains "uid" then "uid" will start from a new line every time..

any other answer???
# 6  
Old 06-01-2009
# sed 's/uid\
> uid/g' <file_name>
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. UNIX for Dummies Questions & Answers

Replace string including newline

Hi, I am trying to do some transformation on a large file and I am getting some troubles trying remove newlines only when the last character of a line is a symbol (in this case is a pipe "|"). I have tried with sed like this: sed -i 's/|\n/|/g' my_file or sed -i 's/|$/|/gg' my_file... (5 Replies)
Discussion started by: ngb
5 Replies

3. Shell Programming and Scripting

Replace newline in a string

I have a string like below: {\rtf1\fbidis\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}{\f1\fnil MS Sans Serif;}} \viewkind4\uc1\pard\ltrpar\lang2057\f0\fs16 19/11/2010 SOME DESCRIPTION. \par \lang1033\f1\par } I have to replace the newline character with null in the... (8 Replies)
Discussion started by: Pratik4891
8 Replies

4. Shell Programming and Scripting

Replace String With Newline

Hi, I'm struggling with a string replacement. I have an XML file which is in the following layout <FUNCTION> <PRODUCTS> <PRODUCT CODE="PRODUCE" ACTION="amend" VALIDATE="no"> <SUPPLIER PRODUCT="PRODUCT" ACTION="amend" CODE="SUPPLIER"> <STOCK_QUANTITY DATA="21"/> ... (15 Replies)
Discussion started by: Ste_Moore01
15 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format

Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now. I have the following in my xml file: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

8. UNIX for Dummies Questions & Answers

replace text string with a newline

I want to replace a text string with a newline. I have a long text file of random characters. I want to replace all the occurences of "pe" with a newline. How can I do that in Unix? There's a thread from 2004 saying that you can do something like this with sed by actually pressing the return... (1 Reply)
Discussion started by: aaronpoley
1 Replies

9. Shell Programming and Scripting

Replace a string with newline

Hi all I have the problem to substitute a string with newline in Perl. Can anybody help me? And also how to replace a string with opening bracket (e.g. (START ) with a whitespace/null character? Thanks in advance. (1 Reply)
Discussion started by: my_Perl
1 Replies

10. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies
Login or Register to Ask a Question