Sponsored Content
Full Discussion: Text Substitution Project
Top Forums Shell Programming and Scripting Text Substitution Project Post 302467696 by dougp23 on Saturday 30th of October 2010 07:18:57 PM
Old 10-30-2010
Thanks for the hints and help!

Methyl, the number of edits is actually not that massive. Assume the run.sed file (which is really my dictionary file) has 2400 lines. Each PHP script has maybe 200 lines, and I have 200 scripts. But each script will only get about 10-15 of those replacements. BTW, my version of sed says GNU 4.2.1 and the -i flag is for "inline edit". But you are absolutely correct, I did something like this once with no backup, and it wasn't right, and I had no way to go back to the old files and try something new! Several backups here. Here's what worked (the whole thing took about 2 minutes on a 2GHz Pent, 1GB Ram, Linux):

run.sed (abbreviated):
Code:
#!/bin/sed -f
s/_BROWSER_TITLE/"School Management System"/
s/_MORE_TEXT/"You need more text"/
s/_BAD_ENTRY/"Your entry is invalid"/
....

The script to iterate through all the files:
Code:
#!/bin/bash

FILES=/home/me/swift200/*.php

for f in $FILES
do
    echo "Processing $f file..."
    ./run.sed -i "$f"
done

I'm still pretty rusty with bash scripts, but it worked! A real oddity, I tried what rdcwayx suggested the other night, thinking that the script would use bash's "built-in" variables of $1, $2, $3, etc. This did not work, and echoing the filename at each point would echo something like

working on script .//home/me/swift200/admin_manage_attendance.php

Which of course would not work. Not sure where the extra slash came from. What WOULD work was using $@ instead of $1. Again, I have no idea why, maybe it's my version of bash/linux/sed, but that was the first time I ever saw using $@.

Again, thanks everyone! Your hints got me in the right direction, and I'm all set now!

Last edited by Scott; 10-30-2010 at 08:43 PM.. Reason: Code tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Update text files in place (string substitution) ??

The auditors have nailed us for world writeable files.... Apparently in years gone by, quite a number of our kornshell scripts have had: umask 000 put in the script. We have been able to turn off world writeable for existing dirs & files, but as these scripts run, new files keep getting... (1 Reply)
Discussion started by: kornshellmaven
1 Replies

2. Shell Programming and Scripting

text substitution

hi, in a text file i want to find the lines which contains A and B,and if these lines do not contain C and D. i want to substitute X with Y. how can i achive these? i tried with sed and awk, but couldnt succeed. (3 Replies)
Discussion started by: yakari
3 Replies

3. Solaris

SSH doesn't pick up user's project from /etc/project

We have a system running ssh. When a user logs in, they do not get the project they are assigned to (they run under "system"). I verify the project using the command "ps -e -o user,pid,ppid,args,project". If you do a "su - username", the user does get the project they are assigned to (and all... (2 Replies)
Discussion started by: kurgan
2 Replies

4. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

Text substitution & getting file name from url

hi, sorry if this seems trivial. i have a file url.txt which consists of a list of urls (it was supposed to be my wget -i file). however, since the server from which i am trying to download uses redirect, wget dows not remeber the filename of ther original url will save to a file name which is... (3 Replies)
Discussion started by: texttoolong
3 Replies

6. Solaris

what is the use of /etc/project file and project administration commands?

i have two doubts.. 1. what is the use /etc/project file. i renamed this file and when i tried to switch user or login with some user account the login was happening slowly. but when i renamed it to original name it was working fine... why so? 2. unix already has useradd and grouadd for... (4 Replies)
Discussion started by: chidori
4 Replies

7. Shell Programming and Scripting

Linguistic project: extract co-occurrences from text corpus

Hello guys, I've got a big corpus (a huge text file in which words are separated by one or several spaces). I would like to know if there is a simple way - using awk for instance - to extract any co-occurrence appearing at least 3times through the whole corpus for a given word. By co-occurrence,... (7 Replies)
Discussion started by: bobylapointe
7 Replies

8. News, Links, Events and Announcements

A new project was posted on The UNIX and Linux Forums project board.

A new project was posted on your project board. Project title: Bash Shell Tutoring Estimated Budget: $50/hr Start date: Immediately Required skills: Linux, Bash, Shell, UNIX I work as a datawarehouse designer and developer. Although I usually stick to the role of an analyst,... (0 Replies)
Discussion started by: Neo
0 Replies

9. Shell Programming and Scripting

FINDING DUPLICATE PROJECT ( directory project )

I have a project tree like that. after running find command with the -no -empty option, i am able to have a list of non empty directory DO_MY_SEARCH="find . -type d -not -empty -print0" MY_EXCLUDE_DIR1=" -e NOT_IN_USE -e RTMAP -e NOT_USEFULL " echo " " > $MY_TEMP_RESULT_1 while... (2 Replies)
Discussion started by: jcdole
2 Replies
UPDATE-METAINIT(1)					User Contributed Perl Documentation					UPDATE-METAINIT(1)

NAME
update-metainit - Generates init scripts SYNOPSIS
update-metainit [--remove initname [--purge] ] DESCRIPTION
Metainit solves the problem of writing good init scripts. Instead of manually creating these important files, they are derived from a declaritive description in the metainit files in /etc/metainit. These files can be shipped with packages or created by the local adminis- trator. If update-metainit called without argument, it will regenerate init scripts for all the files in /etc/metainit. The generated files contain a large warning in form of a comment that they will be overridden. Modifications are preferably done in the files in /etc/metainit and made effective by running update-metainit. If needed, the administrator can prevent modified init files by removing the warning comment. OPTIONS
--remove initname This command will remove any generated and non-modified scripts that were created by the metainit file with the name initname. --purge Only usable with --remove. Will remove the generated files even if modified. SEE ALSO
dh_metainit(1) AUTHOR
Joachim Breitner <nomeata@debian.org> perl v5.8.8 2007-07-30 UPDATE-METAINIT(1)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy