Sponsored Content
Top Forums Shell Programming and Scripting Can sed replace every 2 instances it finds in a file? Pattern. Post 302401516 by EXT3FSCK on Saturday 6th of March 2010 03:10:08 PM
Old 03-06-2010
Java Can sed replace every 2 instances it finds in a file? Pattern.

My goal is to make a script to find/replace the variable "PORT" with a unique number.

Like the following

Code:
<VirtualHost 174.120.36.236:PORT>
    ServerName architect.com.ph
    ServerAlias www.architect.com.ph
    DocumentRoot /home/architec/public_html
    ServerAdmin webmaster@architect.com.ph
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/architect.com.ph combined
    CustomLog /usr/local/apache/domlogs/architect.com.ph-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    ## User architec # Needed for Cpanel::ApacheConf
    <IfModule mod_suphp.c>
        suPHP_UserGroup architec architec
    </IfModule>
    <IfModule !mod_disable_suexec.c>
        SuexecUserGroup architec architec
    </IfModule>
    ScriptAlias /cgi-bin/ /home/architec/public_html/cgi-bin/


    # To customize this VirtualHost use an include file at the following location
    # Include "/usr/local/apache/conf/userdata/std/2/architec/architect.com.ph/*.conf"

</VirtualHost>

        backend architect.com.ph {
                set backend.host = "architect.com.ph";
                set backend.port = "PORT";
        }

The problem is that inside this file there are hundreds of virtualhosts, and other config files.

I am wondering if sed can go through a pattern of every 2 instances it finds of "PORT" to be replaced with a unique number, or better yet sequential, is this possible?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED Search Pattern and Replace with the Pattern

Hello All, I have a string "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031", and I just want to extract LLSV1, but I dont get the expected result when using the sed command below. # echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | awk '{print... (4 Replies)
Discussion started by: racbern
4 Replies

2. Shell Programming and Scripting

pattern replace inside text file using sed

Hi, I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file. For Example: If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained. But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Discussion started by: meharo
4 Replies

3. Shell Programming and Scripting

How to replace the last pattern using sed?

myfile: AAAaaa BBBbbb CCCccc AAAeee DDDddd how to replace the last AAA as EEEEE using sed? like this: AAAaaa BBBbbb CCCccc EEEEEeee DDDddd (14 Replies)
Discussion started by: vistastar
14 Replies

4. UNIX for Dummies Questions & Answers

Using sed command to remove multiple instances of repeating headers in one file?

Hi, I have catenated multiple output files (from a monte carlo run) into one big output file. Each individual file has it's own two line header. So when I catenate, there are multiple two line headers (of the same wording) within the big file. How do I use the sed command to search for the... (1 Reply)
Discussion started by: rebazon
1 Replies

5. Shell Programming and Scripting

Replace a pattern in a file with a generated number using sed or awk

my file has thousands of line but let me show what i want to achieve... here is one line from that file cat fileName.txt (2,'','user3002,user3003','USER_DATA_SINGLE',1,0,0,'BACKUP',2,NULL,0,450,NULL,NULL,'','2011-05-10... (13 Replies)
Discussion started by: vivek d r
13 Replies

6. Shell Programming and Scripting

sed finds nothing but it changes file's timestamp

I must go through some files to change a certain string within text files to another string. I use openSUSE and folders are mounted by cifs. Text to be replaced (only in .m extension) is U:\FOLDER and new string is N: That works fine with spaces in directory names etc., but this process ... (5 Replies)
Discussion started by: Pappa41
5 Replies

7. Shell Programming and Scripting

sed command to replace two character pattern with another pattern

Not able to paste my content. Please see the attachment :-( (2 Replies)
Discussion started by: vivek d r
2 Replies

8. Shell Programming and Scripting

Pattern replace from a text file using sed

I have a sample text format as given below <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456" From="1626711840902323"... (3 Replies)
Discussion started by: my_Perl
3 Replies

9. UNIX for Beginners Questions & Answers

sed replace pattern

I have a file with multiple lines, all in the same format. For each line, I need to replace the sequence of digits after the last : with a new value, but keep the single quote at the end of the line. Example: Input: ( two lines of file) Name: 'text1:200/text2:1.2.3.4' Name2:... (19 Replies)
Discussion started by: Beginner101
19 Replies

10. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies
HTCONFIG(1)						       GLOBAL cgi Utilities						       HTCONFIG(1)

NAME
htconfig - create/update GLOBAL gsearch.cgi files SYNOPSIS
htconfig -I [-v] [-z] [-a action] [-p pathdb] cgidir htconfig --install [--verbose] [--makeghtml] [--formaction=cgi] [--pathdb=paths-file] cgidir htconfig [-v] [-u url] [-d GTAGSDBPATH] [-s GTAGSROOT] [htmldir] htconfig [--verbose] [--url=base-url] [--tags=GTAGSDBPATH] [--src=GTAGSROOT] [htmldir] DESCRIPTION
htconfig is a program to create and maintain a centralised cgi interface for hypertext created with Shigio Yamaguchi's GLOBAL source code tag system. htconfig is used to create the necessary scripts in your system's favoured cgi-bin directory, and to maintain the paths database, which gsearch.cgi uses to locate your hypertext source and the associated TAGS files. This enables GLOBAL's hypertext search facilities without requiring you to enable cgi execution outside of a system-wide cgi-bin directory. htconfig acts as a backend for the htmake(1) script which automates the process of generating hypertext source with the relevant options to htags(1) and adding required entries to the paths database. htconfig can also optionally create a centralised ghtml.cgi script, for users of the htags -c option which creates compressed hypertext with a .ghtml suffix. OPTIONS
Common Options -v, --verbose uh, you get one guess. Install Options These options are to be used during the initial installation of the centralised cgi mechanism. If you installed this as a binary package you probably won't need to use these and can skip to the next section. Otherwise you must run htconfig --install with any or all of the following options before using htmake(1) or any of the Database Options of htconfig. -I, --install Creates gsearch.cgi in cgidir and creates the config file /etc/gtags/htmake.conf if it doesn't already exist. You must specify cgidir, there is no default. -a action, --formaction=action Puts the default submit action for hypertext created with htmake(1) into /etc/gtags/htmake.conf when that file is created. You can edit htmake.conf at any time to change it, or override its setting from the command line. Setting this to the absolute url of gsearch.cgi on your system is probably what you want here unless you understand why not. eg. --formaction=http://host/cgi-bin/gsearch.cgi -p paths-database, --pathdb=paths-database Puts the filesystem location of the paths database file into /etc/gtags/htmake.conf when that file is created. You must define a location for the paths database either with this option or by editing the GSPATHDATA option in htmake.conf before using htmake(1) or the Database options of htconfig(1). Due to file system variations there is no default for this. For Debian GNU/Linux systems the preferred location is: /var/lib/gsearch/pathdata One suggestion for *BSD systems would be: /var/gsearch/pathdata -z, --makeghtml Installs the ghtml.cgi script in cgidir. You will also need edit your http server config to make use of this. For apache this in- volves ensuring mod_mime and mod_actions are loaded and adding lines like: AddHandler htags-gzipped-html ghtml Action htags-gzipped-html /cgi-bin/ghtml.cgi to your httpd.conf file. Database Options These options are used to configure and maintain the path database that allows gsearch.cgi to find your hypertext source and it's tag files. You should call htconfig with these options when you move files or create a new hypertext source tree with htags(1). The path database requires the hypertext source to be generated with a unique id using the htags --id=someid option. When creating a new hypertext source tree you may prefer to use htmake(1) which invokes htags with the desired options and then calls ht- config to update the path database as a single operation. htmldir specifies the filesystem path to the root of your hypertext source tree. It defaults to ./HTML in line with htags(1) defaults and is not required at all if the --url option is used and your system has lynx(1) availiable, -u base-url, --url=base-url the base url of your hypertext source. For best results always use absolute url's here. eg. http://host/~user/mysource It defaults to file:/htmldir -d gtagsdbpath, --tags=gtagsdbpath the filesystem path to the GTAGS files associated with your source. It defaults to the current directory. -s gtagsroot, --src=gtagsroot the filesystem path to the root of your original plaintext source tree. It defaults to the current directory. EXAMPLES
To initialise and install cgi and config files: # htconfig -I -a http://host/cgi-bin/gsearch.cgi -p /var/lib/gsearch/pathdata /usr/lib/cgi-bin To generate hypertext and update path database: $ cd /usr/src/myprog $ gtags $ htags --action=http://host/cgi-bin/gsearch.cgi --id=uniqueid --nocgi $ htconfig or more simply: $ cd /usr/src/myprog $ gtags $ htmake To update the path database if you relocate your hypertext, TAGS files, or the original program source: $ htconfig -u new-url -d new-gtagsdbpath -s new-gtagsdbroot newhtmldir some of these option may be inferred - See their defaults under Database Options The user running htconfig or htmake must have write permission for the path database. FILES
/etc/gtags/htmake.conf gsearch.cgi ghtml.cgi path database BUGS
htconfig currently has no automatic housekeeping mechanism for 'stale' database entries. This should be fixed RSN. There is presently no file locking mechanism for database updates. Attempting simultaneous updates could prove 'surprising' ^_^ This is alpha software - expect anything! SEE ALSO
htmake(1), htags(1), global(1). AUTHOR
Ron Lee <ron@debian.org> CREDITS
Thanks to Shigio Yamaguchi <shigio@gnu.org> for creating GLOBAL and releasing it as free software. A truly cool productivity tool! Debian GNU/Linux 27 March 1999 HTCONFIG(1)
All times are GMT -4. The time now is 04:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy