Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Give the vi command for replacing all occurances of the string "DOS" with the string "UNIX" in the whole document that is currently being edited. what are the commnads for replacing all occurances of the strings "DOS" and "WINDOWS" with the string "UNIX" from all lines that start or end with these strings in the document being edited?
2. Relevant commands, code, scripts, algorithms:
3. The attempts at a solution (include all code and scripts):
Part 1 was easy,
But part two is what I am having trouble with. I can replace all instances at the end of the line, but not the instances IN the line that end with that word. My best solutions are
But they only replace the test "DOS" or "WINDOWS" at the beginning or end of the line with "UNIX"
So "DOS and WINDOWS are better than OS/2" Would become,
"UNIX and WINDOWS are better than OS/2" when it should be,
"UNIX and UNIX are better than OS/2"
I've tried google and the text book doesn't help at all with this. I know I have to be close but I just can't figure it out.
Thanks
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Athabasca University, Calgary(I'm in Thunder Bay), Canada, Dr. Mahmoud Abaza, COMP315
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Last edited by zxmaus; 08-11-2011 at 11:56 PM..
Reason: added code tags
Just a hint. "%" is an address for vi command to operate on. It is the whole file, but this address can be a regex (or line numbers).
You are doing very well and I don't want just to give you a solution.
If i am not mistaken the % sign will make vi search every line in the file.
I have tried this, and it works, (I found another example in a page somewhere) but can someone break it down for me? I don't follow the first part of it.
:g/^\(DOS\|WINDOWS\)/s/\(DOS\|WINDOWS\)/UNIX/g
:g/\(DOS\|WINDOWS\)$/s/\(DOS\|WINDOWS\)/UNIX/g
I don't understand the :g at the beginning or why the s is after the line beginning with section....
You do not need "g(lobal)" command here. You just need an address of lines for your substitution. Just remove it and you get an usual ex command pattern:
Btw, try one cmd with a such address :/^...|\1$/ s... I'm not sure whether it will work but you can check.
If i am not mistaken the % sign will make vi search every line in the file.
I have tried this, and it works, (I found another example in a page somewhere) but can someone break it down for me? I don't follow the first part of it.
:g/^\(DOS\|WINDOWS\)/s/\(DOS\|WINDOWS\)/UNIX/g
:g/\(DOS\|WINDOWS\)$/s/\(DOS\|WINDOWS\)/UNIX/g
I don't understand the :g at the beginning or why the s is after the line beginning with section....
I have one big file of size 9GB (big_file.txt). This big file has sentences and paragraphs like any usual English document. I have another file consisting of replacement strings for sed to use. The file name is replace.sed and each entry in one line looks like this:
s/\<shout\>/shout/g
s/\<b is... (2 Replies)
Hi Team,
I am new to unix, please help me in this.
I have a file named properties.
The content of the file is :
##Mobile props
east.url=https://qa.east.corp.com/prop/end
west.url=https://qa.west.corp.com/prop/end
south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Hi,
I am looking for bash or awk script to solve the following.
Input File 1:
>Min_0-t10270-RA|>Min_0-t10270-RA protein AED:0.41 eAED:0.46 QI:0|0|0|0.25|1|1|4|0|190
MIGLGFKYLDTSYFGGFCEPSEDMNKVCTMRADCCEGIEMRFHDLKLVLEDWRNFTKLST
EEKRLWATPAAEDFF
>Min_0-t10271-RA|>Min_0-t10271-RA protein... (5 Replies)
I am writing code for a binary search tree search and when I compile it i am getting strange errors such as, " /tmp/ccJ4X8Xu.o: In function `btree::btree()':
project1.cpp:(.text+0x0): multiple definition of `btree::btree()' "
What does that mean exactly?
tree.h
#ifndef TREE_H
#define... (1 Reply)
Dear All,
i want to search particular string and want to replance next line value.
following is the test file.
search string is
tmp,???
,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50
tmp,123 --- if match tmp,??? then... (3 Replies)
Hi,
The following code loops through every file with an error extension and then loops through all XML files in that directory and replaces the target character @ with / . The problem I have is that if there is more than one occurance of @ in each individual file it doesn't replace it. Any... (2 Replies)
Hello,
I really would appreciate some help with a bash script for some string manipulation on an SQL dump:
I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump.
This is quite easy with sed:
sed -e... (1 Reply)
Hi,
In a file FILE, the following lines appear :
WORD 8 8 8
ANOTHERWORD blabla
...
Directly in the prompt, if I type
$sed '/WORD/s/8/10/g' FILE
it replace the 8's by 10's in file :
$cat FILE
WORD 10 10 10
ANOTHERWORD blabla
... (9 Replies)
Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
I want to carry out search & replace for the paths mentioned in the file with the help of vi.
'abc/' to be replaced by 'abc/data'
When I use command in vi as below -
%s/abc//abc/data/g
it gives me an error.
How we should deal with '/' part in string for vi search & replace?
... (6 Replies)