The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 06:11 AM
Want to replace characters arndorff Shell Programming and Scripting 5 01-29-2008 04:05 PM
Replace string B depending on occurence of string A hemangjani Shell Programming and Scripting 1 12-05-2006 05:10 PM
Replace Characters... lgardner17325 UNIX for Dummies Questions & Answers 8 10-26-2006 05:04 PM
Replace characters in a string using their ascii value roops Shell Programming and Scripting 2 03-04-2005 01:51 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 08-28-2003
slaubhan slaubhan is offline
Registered User
  
 

Join Date: Nov 2002
Location: Oklahoma
Posts: 2
Replace string and delete extra characters

Hopefully someone can help out here. This is probably fairly basic, but I've searched and tried several variations of the solutions presented in these forums, so I'll go ahead and ask.

How can I locate a string in a file, delete the characters after the string and then replace the string with a new string?

Currently I have this, which is getting me close to a solution, but I can't get the extra characters removed:

for file in test_program; do

sed 's/OUTPUT='/'OUTPUT='$file/g $file > new_$file

done

Here is the test_program file that I am testing with:

This is a test
This is a test
/OUTPUT=("This is a test")
This is a test

Here are the results after running my script:

This is a test
This is a test
/OUTPUT=test_program("This is a test")
This is a test

I just need to have the script get rid of ("This is a test") and it will work fine for what I am trying to do, which is make this change to several thousand files at one time. Any assistance would be appreciated. I've got other ways to do this, but now that I've embarked down the Unix path, I want to see how this is done.
  #2 (permalink)  
Old 08-28-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
try:
sed 's/OUTPUT=.*/OUTPUT='$file'/' $file > new_$file
  #3 (permalink)  
Old 08-28-2003
slaubhan slaubhan is offline
Registered User
  
 

Join Date: Nov 2002
Location: Oklahoma
Posts: 2
Thank you!! That did the trick. I had already tried with the asterisk, but I left out the period.
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 07:50 AM.


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