Sponsored Content
Full Discussion: Text Substitution Project
Top Forums Shell Programming and Scripting Text Substitution Project Post 302467534 by dougp23 on Friday 29th of October 2010 05:12:19 PM
Old 10-29-2010
Text Substitution Project

History: large open source PHP project, school management program. Comprises about 200 scripts. Had another developer for awhile, and he wanted a version in German, so he edited all the scripts and replaced text that would show up in the browser with variables (i.e. instead of "Click Here", we have _PAGE_TEXT_CLICK). There was one big file with 2400 variables defined (DEFINE _PAGE_TEXT_CLICK "Click Here". He has since moved on, and the demand for a multi-lingual project never materialized. As I am now sole code-maintainer, I find it very cumbersome to make changes to the project, and now want to go back to an English only version.

I have been trying to create a script that will just do a massive 'search and replace' through all 200 scripts (realizing that each script might have about 10 replacements that need to be done, so many attempts at replacing text would fail, as every DEFINE statement is unique).

OK, that's the history! I created this massive 'run.sed' file that looks like this:

Code:
sed -i 's|_TEACHER_EDIT_STUDENT_1_NOTES|\"Notes\"|'
sed -i 's|_TEACHER_EDIT_STUDENT_1_BIRTHCITY|\"Birth City\"|'
sed -i 's|_TEACHER_EDIT_STUDENT_1_BIRTHSTATE|\"Birth State\"|'
sed -i 's|_TEACHER_EDIT_STUDENT_1_BIRTHCOUNTRY|\"Birth Country\"|'
sed -i 's|_TEACHER_EDIT_STUDENT_1_PRVS_SCHOOLNAME|\"Prvs School Name\"|'
sed -i 's|_TEACHER_EDIT_STUDENT_1_PRVS_SCHOOLADDRESS|\"Prvs School  Address\"|'
[chopped, 2400 lines]


Single attempts aimed at a single file work, so the syntax appears to be fine.

My bash file that should iterate through the scripts looks like this:

Code:
#!/bin/bash
FILES=/home/me/swift200/*.php
for f in $FILES
do
  echo "Processing $f file..."
  ./run.sed $f
done

The script is executable, I am doing this as root, none of my PHP files have spaces in the name, and I am executing this from the directory that contains the PHP files.

When I run it, many of these go scrolling by:

Quote:
sed:no input files
When I reduce run.sed to just one line, it successfully searches and replaces all occurences of that string in all the php files. I am truly at wits end with this, and would appreciate any insight at all.

Thank you!
This User Gave Thanks to dougp23 For This Post:
 

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
fixnt(1)							      Debian								  fixnt(1)

NAME
fixnt - Filter for the Windows NT postscript printer driver. SYNOPSIS
fixnt < BADFILE.ps > GOODFILE.ps DESCRIPTION
The Windows NT postscript driver has a tendency to make broken postscript files, that are incompatible with psutils. fixnt is a filter that fixes these problems, allowing the use of psnup(1). The filter takes the broken postscript file on stdin, and outputs a fixed postscript file on stdout. It has no other form for invocation and takes no options on the command-line. OPTIONS
fixnt takes no options. BUGS
fixnt does not check for NTPSOct94. For a workaround, use a sed(1) command to replace 'NTPSOct94' with 'NTPSOct95', like so: sed 's/NTPSOct94/NTPSOct95/g' This is particularly important for Windows NT 3.5 users. AUTHOR
fixnt was written by Holger Bauer <Holger.Bauer@topmail.de>, Michael Rath <rath@itsm.uni-stuttgart.de>, and Akim Demaille <demaille@inf.enst.fr>. REPORTING BUGS
Report bugs to the Authors, but avoid sending large postscript files. Patches are always welcome; send to <bauer@itsm.uni-stuttgart.de>. SEE ALSO
psnup(1), sed(1) a2ps February 2003 fixnt(1)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy