Looping and using Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping and using Sed
# 1  
Old 01-31-2008
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
# 2  
Old 02-01-2008
Post an example of the original content of the files and the expected output you want.

Regards
# 3  
Old 02-03-2008
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
# 4  
Old 02-04-2008
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
# 5  
Old 02-04-2008
Computer 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.

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Looping and sed

Hi, I've got text files (say file1 and file2) in a directory (say directory1) with several columns like this: a b c d a b c de f g h e f g hI need to add a header to the files in directory1 and the names of the columns must contain an identifier from another text file (say file3) like this:... (4 Replies)
Discussion started by: zajtat
4 Replies

2. Shell Programming and Scripting

Looping

Hey guys, so I am trying to do a loop script that will go through each folder (no gui so just each domain has a folder) and grab out the databases being used on that domain. I know I would use mysql -e "show databases where not 'information_schema';" once in each directory to pull the actual... (3 Replies)
Discussion started by: dough
3 Replies

3. Shell Programming and Scripting

Sed pattern space/looping conundrum

Although my sed skills are gradually developing, thanks in large part to this forum, I'm having a hard time dealing with pattern space and looping, which I suspect is what I'll need a better handle on to figure out my current issue, which is converting a multi line file like this: ... (4 Replies)
Discussion started by: tiggyboo
4 Replies

4. Shell Programming and Scripting

Looping

Hi, Now I have written a script which sorts the records in the file and splits them according to some condition. Now, I need to modify the script so that it reads all the files one after the other and does the sorting & splitting. Pls help me in reading all the files in a directory and... (8 Replies)
Discussion started by: Sunitha_edi82
8 Replies

5. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

6. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

7. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

8. Shell Programming and Scripting

looping

Hi I have around 100 users in sun server and have default home directory in /usr/home/<username> I want to clean their home directory time to time to make free space on root, as users generate many output files during usage of application. My idea is, generate a file with following command... (4 Replies)
Discussion started by: ishir
4 Replies

9. Shell Programming and Scripting

looping and awk/sed help

I am pretty new to this, but imagine what I am trying to do is possible iI am trying to make an automated DB comparison tool that selects all columns in all tables and compares them to the same thing in another DB. anyway I have created 2 files to help with this the first file is a... (13 Replies)
Discussion started by: Zelp
13 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question