Replacing multiple asterisks in vi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing multiple asterisks in vi
# 1  
Old 09-24-2017
Replacing multiple asterisks in vi

i need to replace all occurrences of "period asterisk" as it is shown in this:

Code:
blah blah .*:.*:.* blah blah

with:

Code:
[0-9][0-9]:[0-9][0-9]:[0-9][0-9]

so that the end result looks like this:

Code:
blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah

I tried different variations of the following but it didint work:

Code:
%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g

# 2  
Old 09-24-2017
Hi,

I just tried this in vim, and the following command worked for me:

Code:
1,$ s/\.\*/[0-9][0-9]/g

This turned the following string:

Code:
blah blah .*:.*:.* blah blah

into this:

Code:
blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah

Caveats: this was a quick one-liner in vim for iOS, so your mileage may vary as they say. But this appears to work for this very specific string in these very specific circumstances.
This User Gave Thanks to drysdalk For This Post:
# 3  
Old 09-25-2017
I think this works in all vi and vim variants and in all OSes.
Further it works in all sed versions, where the 1,$ (all lines) selector can be omitted because it is default.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

3. Shell Programming and Scripting

Replacing multiple extensions

HI, I have some csv files with mutiple extensions, I want to remove all the extensions and keep only the .csv extension. anybody can suggest me how to do this. source files 1.txt.csv.txt.csv.csv.txt.csv 2.csv.txt.csv.txt.csv.txt target 1.csv 2.csv --Wang (1 Reply)
Discussion started by: wangkc
1 Replies

4. UNIX for Dummies Questions & Answers

Replacing multiple characters

I have a file as follows ggsnApnDownlinkBytes.X ggsnApnDownlinkDrops.X ggsnApnDownlinkPackets.X ggsnApnName.X ggsnApnUplinkBytes.X ggsnApnUplinkDrops.X ggsnApnUplinkPackets.X ggsnApnDownlinkBytes.Y ggsnApnDownlinkDrops.Y ggsnApnDownlinkPackets.Y ggsnApnName.Y ggsnApnUplinkBytes.Y... (7 Replies)
Discussion started by: rob171171
7 Replies

5. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

6. Shell Programming and Scripting

need to replace asterisks

I need to replace occurrences of twelve asterisks "************" with the string " 0000000.00" . Note that there are two spaces in front of the first zero. How can I do this using awk or sed? (3 Replies)
Discussion started by: mustang_9333
3 Replies

7. Shell Programming and Scripting

Replacing text from multiple files at multiple location

Hi, I have many files scattered in all different folders. I want to replace the text within all the files using a single command ( awk, sed...) Is it possible? example find all the files in which there is text "memory" and replace it with "branded_memories". the files can be at the... (2 Replies)
Discussion started by: rudoraj
2 Replies

8. Shell Programming and Scripting

Replacing string in multiple files

Hi, I need to replace the string 'abcd' with 'xyz' in a file sample.xml This sample.xml is also present in the subdirectories of the current directory. Eg, If I am in /user/home/ the sample.xml if present in /user/home/ /user/home/folder1/ /user/home/folder2/... (3 Replies)
Discussion started by: arulanandsp
3 Replies

9. Shell Programming and Scripting

Double asterisks

When I go$ echo *I get a directory listing. When I go$ echo * *I get a directory listing, followed by a second identical directory listing. When I go$ echo **I only get one directory listing. What happens to the second asterisk in this case? Why doesn't it expand? I haven't been able to sleep... (2 Replies)
Discussion started by: na5m
2 Replies

10. Shell Programming and Scripting

replacing multiple lines

i have a file : sample1.txt OBJECT="POINT" ACTION="REDEFINE" POINT_NAME="ABCD001G " GHYT_POPRIORITY_1="1" GHYT_POPRIORITY_2="1" GHYT_POPRIORITY_3="1" GHYT_POPRIORITY_4="1" GHYT_POPRIORITY_USER="1" HIGH_ALARM_PRIORITY_1="1" HIGH_ALARM_PRIORITY_2="1" HIGH_ALARM_PRIORITY_3="1" ... (1 Reply)
Discussion started by: ajnabi
1 Replies
Login or Register to Ask a Question