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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with looping finalight Shell Programming and Scripting 2 05-23-2008 05:35 AM
help on looping using if/for or while sam4now Shell Programming and Scripting 1 04-24-2008 10:33 AM
looping ishir Shell Programming and Scripting 4 09-17-2005 03:52 AM
looping and awk/sed help Zelp Shell Programming and Scripting 13 06-29-2005 01:13 AM
Looping in awk keelba UNIX for Advanced & Expert Users 3 05-31-2002 01:04 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Looping and using Sed

Hi guys

I having som problem trying to use sed to get a file and insert inside another one. I'll try to explain better.

I have a base.txt and using sed(having a array variables) I'm chaging some strings inside this file and saving as base1.txt. until here okay.
Then, I have to get this base1.txt and insert it inside another file called script.txt.
Well, If I didn't have any looping so far so good. Then, when the script restart, it has to change the base file again, with a different variable(until here okay), and then get this base1.txt again and insert at the same old file script.txt.

The problem is, Sed cleans out the file when I overwrite it. I tried to rename files, but I just can't reach the logic of doing this...
Any suggestion would be a lot appreciatted.

Thank you in advance.

Rodrigo Guimaraes
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-01-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,662
Post an example of the original content of the files and the expected output you want.

Regards
Reply With Quote
  #3 (permalink)  
Old 02-03-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Hi Franklin,

Thanks for your attention.

this is the code

# Changing the Strings
sed -e s/INICIO/$startframe/g \
-e s/FIM/$endframe/g \
-e s/TEMPOINICIAL/$TEMPO1/g \
-e s/TEMPOFINAL/$TEMPO2/g \
-e s/epXXX/ep${EP}/g \
-e s/scXXX/sc${SC}/g \
-e s/shXXX/sh${SH}/g \
-e s/NAME/${i}/g < ${tmpFolder}filesin_line.txt > ${tmpFolder}filesin_line1.txt
sed '$ r' '${tmpFolder}filesin_line1.txt'' < ${tmpFolder}filesin_line1.txt > ${tmpFolder}filesin_lineNEW.txt
rm ${tmpFolder}filesin_line1.txt
done
exit

-------
filesin_line.txt ( this is the first file that has to be inserted into the next one (filesin_lineNEW.txt ))

I don't know if I'm explaining right. But when the looping happens, sed can't overwrite the file (filesin_lineNEW.txt) and I don't know what do it to make sed add the previous modified file.

Please let me know if explanining well...sorry.
Thanks
Reply With Quote
  #4 (permalink)  
Old 02-04-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,662
It's still not clear to me, do you want to append filesin_line1.txt to filesin_lineNEW.txt?
In that case you can do something like:

Code:
cat filesin_line1.txt >> filesin_lineNEW.txt
If not, clarify your question.

Regards
Reply With Quote
  #5 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Talking Thanks!!!

Hi Franklin

I did a small test here outside the script with your line using cat and it seems it worked. Wow! That's great! Sometimes are so many commands that I get confused what to use...
Thanks a lot for your help and your attention Franklin.

Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0