Sponsored Content
Full Discussion: Matching and replacing text
Top Forums Shell Programming and Scripting Matching and replacing text Post 302325562 by xzen123 on Monday 15th of June 2009 01:35:21 PM
Old 06-15-2009
Matching and replacing text

Im new to using perl scripting, and i was wondering if anyone could help me, I need to create a cgi file that when it runs it opens a file looks through all the words, and replace the word hello with goodbye, ive been looking around and someone said to use an If statement, but ive found no other site that explains how to open a file, create a new file and save the converted text to it. if anyone could help me it would be greatly appreciated. the code the person provided is :
Code:
if($line =~ /MatchText/){
    $line =~ s/ReplaceMe/REPLACED/gi;
}

I understand how this works, i just dont know how to create the rest of the file.

if anyone could explain the process of creating this file, or knows a good place with a tutorial would be verry much appreciated.

Last edited by xzen123; 06-15-2009 at 02:45 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all except for the matching pattern

Hi all I need to replace all characters in a file except for the matching pattern eg. I need to replace all character with '*' except for the pattern "abc" Input "sdfhgsdf abc ##%$#abcsdfh sdfjkfff" Output "******abc******abc*************" Request for single liner solution (1 Reply)
Discussion started by: raghav288
1 Replies

2. Shell Programming and Scripting

Matching and replacing text with case transformations

Hi, I am trying to edit an XML file automatically but my regex and shell script knowledge is very limited. I would appreciate your help fellows. The XML file has this structure: <?xml version="1.0" encoding="UTF-8"?> <map map_file="maps/world.swf" zoom="350%" zoom_x="-115%"... (1 Reply)
Discussion started by: boonymagique
1 Replies

3. Shell Programming and Scripting

AWK - Pattern Matching & Replacing - Performance

Experts, I am a beginner to Unix Shell Scripting We have source as a flat file which contains CTRL+F character as the delimiter. We need to count the number of records in the file (CTRL+F) to perform file validation Following command being used: awk '{cnt+=gsub(//,"&")}END {print cnt}'... (4 Replies)
Discussion started by: srivijay81
4 Replies

4. Homework & Coursework Questions

Matching and Replacing Characters

I need to write an Unix script to report the number of SQL files in my home directory, ending with .sql . The script should, also, be checking whether there is a file with an underscore in its name. If that is the case, the underscore should be converted to a dash (‐); for example... (1 Reply)
Discussion started by: ronoz-4
1 Replies

5. Shell Programming and Scripting

Pattern Matching & replacing of content in file1 with file2

I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3. Requirement: check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
Discussion started by: siramitsharma
4 Replies

6. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

7. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

8. Shell Programming and Scripting

Matching and Replacing file lines starting with $

Here is the task that I was presented with: I am dealing with about a 10,000 line input deck file for an analysis. About 10 separate blocks of around 25 lines of code each need to be updated in the input deck. The input deck (deckToChange in the code below) comes with 2 separate files. File 1... (5 Replies)
Discussion started by: tiktak292
5 Replies

9. Shell Programming and Scripting

awk Array matching and replacing from master file.

I have an awk related question that I was hoping you all could help with. I am given 2 input files named OLDFILE and NEWFILE, and a Master file named MASTERFILE. They can be seen below. OLDFILE: a a a a a f g 4 5 7 8 1 2 3 (1 Reply)
Discussion started by: tiktak292
1 Replies

10. Shell Programming and Scripting

Replacing first field of file2 with the second filed of file1 for matching cases

Dear All, Need your help..:D I am not regular on shell scripts..:( I have 2 files.. Content of file1 cellRef 4};"4038_2_MTNL_KALAMBOLI" cellRef 1020};"4112_3_RAINBOW_BLDG" cellRef 134};"4049_2_TATA_HOSPITAL" cellRef 1003};"4242_3_HITESH_CONSTRUCTION" cellRef... (6 Replies)
Discussion started by: ailnilanjan
6 Replies
ENGLISH(5)							File Formats Manual							ENGLISH(5)

NAME
english - flag format for English ispell dictionaries DESCRIPTION
English dictionaries for ispell(1) supports 3 prefix and 14 suffix flags. For a detailed description of how ispell handles flags and capi- talization, see ispell(5). This manual page only describes flags usable in dictionaries built using the english.aff affix file. In the following discussion of the flags, let # and @ be "variables" that can stand for any letter. Upper case letters are constants. "..." stands for any string of zero or more letters, but note that no word may exist in the dictionary which is not at least 2 letters long, so, for example, "fly" may not be produced by placing the "Y" flag on "f". Also, no flag is effective unless the word that it cre- ates is at least 4 letters long, so, for example, "wed" may not be produced by placing the "D" flag on "we". In the following list, an asterisk indicates that a flag participates in cross-product formation (see ispell(5)). The meaning of the prefix flags is as follows: *A ... --> re... as in cover --> recover *I ... --> in... as in firm --> infirm *U ... --> un... as in able --> unable The meaning of the suffix flags is as follows: V ...e --> ...ive as in create --> creative if # .ne. e, ...# --> ...#ive as in prevent --> preventive *N ...e --> ...ion as in create --> creation ...y --> ...ication as in multiply --> multiplication if # .ne. e or y, ...# --> ...#en as in fall --> fallen *X ...e --> ...ions as in create --> creations ...y --> ...ications as in multiply --> multiplications if # .ne. e or y, ...# --> ...#ens as in weak --> weakens H ...y --> ...ieth as in twenty --> twentieth if # .ne. y, ...# --> ...#th as in hundred --> hundredth *Y ...y --> ..ily as in messy --> messily if # .ne y, ...# --> ...#ly as in quick --> quickly *G ...e --> ...ing as in file --> filing if # .ne. e, ...# --> ...#ing as in cross --> crossing *J ...e --> ...ings as in file --> filings if # .ne. e, ...# --> ...#ings as in cross --> crossings *D ...e --> ...ed as in create --> created if @ .ne. a, e, i, o, or u, ...@y --> ...@ied as in imply --> implied if # .ne. e or y, or (# = y and @ = a, e, i, o, or u) ...@# --> ...@#ed as in cross --> crossed or convey --> conveyed T ...e --> ...est as in late --> latest if @ .ne. a, e, i, o, or u, ...@y --> ...@iest as in dirty --> dirtiest if # .ne. e or y, or (# = y and @ = a, e, i, o, or u) ...@# --> ...@#est as in small --> smallest or gray --> grayest *R ...e --> ...er as in skate --> skater if @ .ne. a, e, i, o, or u, ...@y --> ...@ier as in multiply --> multiplier if # .ne. e or y, or (# = y and @ = a, e, i, o, or u) ...@# --> ...@#er as in build --> builder or convey --> conveyer *Z ...e --> ...ers as in skate --> skaters if @ .ne. a, e, i, o, or u, ...@y --> ...@iers as in multiply --> multipliers if # .ne. e or y, or (# = y and @ = a, e, i, o, or u) ...@# --> ...@#ers as in build --> builders or slay --> slayers *S if @ .ne. a, e, i, o, or u, ...@y --> ...@ies as in imply --> implies if # .eq. c, s, or t, ...#h --> ...#hes as in lash --> lashes if # .ne. c, s, or t, ...#h --> ...#hs as in cough --> coughs if # .eq. s, x, or z, ...# --> ...#es as in fix --> fixes if # .ne. s, x, z, h, or y, or (# = y and @ = a, e, i, o, or u) ...@# --> ...@#s as in bat --> bats or convey --> conveys P if @ .ne. a, e, i, o, or u, ...@y --> ...@iness as in cloudy --> cloudiness if # .ne. y, or @ = a, e, i, o, or u, ...@# --> ...@#ness as in late --> lateness or gray --> grayness *M ... --> ...'s as in dog --> dog's To summarize more briefly: Prefixes: *A - re *I - in *U - un Suffixes: V - ive *N - ion, tion, en *X - ions, ications, ens H - th, ieth *Y - ly, ily *G - ing *J - ings *D - ed T - est *R - er *Z - ers *S - s, es, ies *P - ness, iness *M - 's SEE ALSO
ispell(1), ispell(5) ENGLISH(5)
All times are GMT -4. The time now is 07:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy