Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 12:34 AM
тАО07-31-2006 12:34 AM
---------------------
Hi,
Somehow I switch from Unix scripting to DOS batch command and need help here:
how to replace a word in a text file, such as "DEVPLOP" to "PRODUCTION", multiple times and save the file, either with original name or different name.
Unix script makes it simple, but DOS command seems to be remote to me.
Any help is appreciated!
Steven
Solved! Go to Solution.
- Tags:
- DOS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 12:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 12:49 AM
тАО07-31-2006 12:49 AM
Re: DOS help
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 12:55 AM
тАО07-31-2006 12:55 AM
Re: DOS help
If you are using a windows system for doing your DOS edit stuff, open the file in "notepad"
then you find under the edit menu, "replace" type in what you wanted to. Also note if you need to enable/disable the match case.
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 01:11 AM
тАО07-31-2006 01:11 AM
Re: DOS help
Any help is appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 01:45 AM
тАО07-31-2006 01:45 AM
Re: DOS help
1) Download sed for DOS:
http://www.student.northpark.edu/pemente/sed/ssed360s.zip
2) Extract sed-3.59.exe to a directory in %PATH%.
3) Rename sed-3.59.exe to sed.exe.
4) cd
5) sed 's/DEVELOP/PRODUCTION/g' < textfile > textfile.new
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 01:54 AM
тАО07-31-2006 01:54 AM
Re: DOS help
one workaround would be to send the text file to a unix machine, do the change and get it back.
of course, it will be easy if and only if it is a once off task.
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 03:04 AM
тАО07-31-2006 03:04 AM
Re: DOS help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 06:56 AM
тАО07-31-2006 06:56 AM
Re: DOS help
I want to try Plan B. Do you have syntac handy so that I can jump right ahead?
Thanks,
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 07:12 AM
тАО07-31-2006 07:12 AM
Re: DOS help
perl -i.save -p -e 's/DEVPLOP/PRODUCTION/g' file1 file2 ...
It will process each file listed and create a backup file1.save, file2.save, ... the modified files will be file1, file2, ...
If you don't want the backup files then omit the -i option.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 07:19 AM
тАО07-31-2006 07:19 AM
Re: DOS help
In Perl, you could substitute the string PRODUCTION for that of DEVELOP in your file "inplace" like this:
# perl -pi.old -e 's/\bDEVELOP\b/PRODUCTION/gi' file
This substitution would occur case-insensitvely. That is, the "i" following the string PRODUCTION means to match the string DEVELOP case-insensitively, and replace every occurance ((g)lobally) with "PRODUCTION".
The "\b" is a "boundry" so that DEVELOP is replaced by PRODUCTION but not DEVELOPMENT.
The switch '-pi.old' tells Perl to print and perform an inplace edit, first preserving a a copy of 'file' as 'file.old'.
As you can otherwise see, the substitution syntax is similar to 'sed'.
If you want to begin to learn Perl, a good start would be O'Reilly's "Learning Perl (3rd Ed)" by by Randal L. Schwartz and Tom Phoenix.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 03:54 PM
тАО07-31-2006 03:54 PM
Re: DOS help
I am not recommending this solution. But for the "old" dos edlin fans this worked on
my Windows 2000 [Version 5.00.2195] box
I could not resist showing this:
Contents of text file to fix called test.txt:
C:\>type test.txt
This is a DEVPLOP system
This is a DEVPLOP system
This is a DEVPLOP system
THIS is a DEVPLOP system
C:\>
The above file is CRLF terminated..
I then create a file called doit, with edlin using the following line commands:
C:\>edlin doit
New file
*i
1:*1RDEVPLOP^ZPRODUCTION
2:*E
3:*^Z
e
C:\>
^Z is "Ctrl"Z
I then ran the following command to change the test.txt "text":
C:\>edlin test.txt < doit
End of input file
*1RDEVPLOP^ZPRODUCTION
1:*This is a PRODUCTION system
2: This is a PRODUCTION system
3: This is a PRODUCTION system
4: THIS is a PRODUCTION system
*E
C:\>
edlin renamed lower case test.txt to upper case TEST.TXT (and left a TEST.BAK copy)
Thanks for letting me use edlin for the first time in many years...
Rory
On my box edlin can be found at
C:\WINNT\system32\edlin.exe
C:\WINNT\system32\dllcache\edlin.exe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 07:15 PM
тАО07-31-2006 07:15 PM
Re: DOS help
;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2006 08:08 PM
тАО07-31-2006 08:08 PM
Re: DOS help
I couldn't really believe it myself. I even found edlin on my XP machine.. I truly have not used it for many years... (I do admit that I have recently used UNIX ed ...)
Do you think this revelation might be a MS plot to still our souls?
:-}
Rory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 02:53 AM
тАО08-01-2006 02:53 AM
Re: DOS help
But I cannot make words replace, either using dos sed, or perl command.
All DEVELOP words remains. Execution went through without error. Syntac is corret. Would that be the windows/dos character issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 03:10 AM
тАО08-01-2006 03:10 AM
Re: DOS help
the perl will work for shure.
- Did you get any error messages?
- You can create a small file as a test case and try.
- You can give as one matching line of that file for inspection.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 03:12 AM
тАО08-01-2006 03:12 AM
Re: DOS help
This should work under Windows:
perl -i.save -p -e "s/DEVPLOP/PRODUCTION/g" file1 file2 ...
Note the double vs. single quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 04:00 AM
тАО08-01-2006 04:00 AM
Re: DOS help
Thanks for the help. It works, and it happens when I try "perl -pi.old -e 's/\bDEVELOP\b/PRODUCTION/gi' file
", which failed to replace any.
Yours is simpler and working.
But everybody's efforts are very appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 04:13 AM
тАО08-01-2006 04:13 AM
Re: DOS help
Consider a file with these lines:
this is DEVELOPMENT DEVELOP
DEVELOP
DEVELOPMENT
# perl -ple 's/\bDEVELOP\b/PRODUCTION/gi' file
...produces:
this is DEVELOPMENT PRODUCTION
PRODUCTION
DEVELOPMENT
...That is, "words" matching DEVELOP are replaced, not any string containing this sequence. You were not very clear defining your requiremnents.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 04:40 AM
тАО08-01-2006 04:40 AM
Re: DOS help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2006 02:50 AM
тАО08-10-2006 02:50 AM
Re: DOS help
perl -pi -e s/DEVPLOP/PRODUCTION/g
- Tags:
- cygwin