The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Inserting a String in a file header. Hari123 Shell Programming and Scripting 3 05-14-2008 10:00 AM
inserting line?? anj UNIX for Dummies Questions & Answers 7 11-03-2007 12:18 PM
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 07:24 AM
Inserting character in every line dakid Shell Programming and Scripting 1 08-25-2006 08:54 AM
inserting a String in the file(s) 2tbee Shell Programming and Scripting 4 04-11-2006 06:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-07-2004
sunil_neha sunil_neha is offline
Registered User
  
 

Join Date: Apr 2004
Location: india
Posts: 7
Inserting new line after match of a fixed string

Hi,

I have a file which contains many occurances of a string say "hellosunil".

I want to insert a newline charcater after all the "hellosunil" strings in the file.

trying to use sed,

sed -e 's/hellosunil/\\nhellosunil/g' file1

sed help says u cannot substitute a regular expression using new line char. so the above thing does not work?

how can i achieve this using sed or any other command.
  #2 (permalink)  
Old 04-07-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
echo abababab | sed 's/b/\
/g'

will replace all of the b's with newline characters. I really typed a newline after the backslash. This makes the sed command a two line command.
  #3 (permalink)  
Old 04-07-2004
sunil_neha sunil_neha is offline
Registered User
  
 

Join Date: Apr 2004
Location: india
Posts: 7
thanks a lot it has worked
  #4 (permalink)  
Old 04-07-2004
javalee javalee is offline
Registered User
  
 

Join Date: Apr 2004
Location: beijing
Posts: 15
Re: Inserting new line after match of a fixed string

Quote:
Originally posted by sunil_neha
Hi,

I have a file which contains many occurances of a string say "hellosunil".

I want to insert a newline charcater after all the "hellosunil" strings in the file.

trying to use sed,

sed -e 's/hellosunil/\\nhellosunil/g' file1

sed help says u cannot substitute a regular expression using new line char. so the above thing does not work?

how can i achieve this using sed or any other command.
using awk:
Code:
awk '{gsub(/hellosunil/,"\nhellosunil");print}'

  #5 (permalink)  
Old 04-13-2004
sunil_neha sunil_neha is offline
Registered User
  
 

Join Date: Apr 2004
Location: india
Posts: 7
I tried the foll. command:

awk '{gsub(/<eCRMver1:Consumer>/, "\n<eCRMver1:Consumer>"); gsub(/<\/eCRMver1:message>/, "\n<\/eCRMver1:message>");print}' $input_file > $tem
p_output_file1

ERROR:

awk: 0602-581 The result <?xml version="1.0" of the gsub function
cannot be longer than 10,239 bytes.
The input line number is 1. The file is /appl/ecrmhome/gb53/VSC.xml.
The source line number is 1.


my VSC.xml is 35000 (and it can be much more ???)

Please suggest.
  #6 (permalink)  
Old 04-13-2004
sunil_neha sunil_neha is offline
Registered User
  
 

Join Date: Apr 2004
Location: india
Posts: 7
taking the entire file in a variable and applying sed WORKS...

total_xml_msg=`cat $input_file`
echo $total_xml_msg | sed 's/<eCRMver1:Consumer>/\
<eCRMver1:Consumer>/g' > $temp_output_file1

good for the time being...
  #7 (permalink)  
Old 04-13-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Try:
sed 's/<eCRMver1:Consumer>/\
<eCRMver1:Consumer>/g' < $input_file > $output_file1
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0