substitution in VI editor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substitution in VI editor
# 1  
Old 03-16-2009
substitution in VI editor

Hi,
I have entries in a log file :

Code:
/tmp/nightly_releases/releases_20090315file1.zip
/tmp/nightly_releases/releases_20090315file2.zip


I want a "/" to be inserted in between directory and the file to complete the path like :

Code:
/tmp/nightly_releases/releases_20090315/file1.zip
/tmp/nightly_releases/releases_20090315/file2.zip

Any script or command for it that i can run from console (not in command promt in VI editor ) please help. Thanks in advance.

Last edited by Yogesh Sawant; 03-25-2009 at 02:06 PM.. Reason: added code tags
# 2  
Old 03-16-2009
try:
Code:
perl -pi -e 's#(releases\_\d+)(file)#\1/\2#' logfile

# 3  
Old 03-16-2009
Thread subject:
Quote:
Originally Posted by bhaskar_m
substitution in VI editor
Quote:
Originally Posted by bhaskar_m
[...](not in command promt in VI editor)[...]
Which one should it be? To do it in VI(m) (as your subject suggests) it would be
Code:
:%s/\(file.\.zip$\)/\/\1/

To do it without VI(m) (as the body of your message suggests), use Yogesh' suggestion, with 2 corrections:
  • There's usually no need to escape an underscore
  • Backrefs (\1, \2) are better written as $1, $2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitution

I am trying to do some substitutions using the substitution operator (:%s) in a text file. I want to replace all A1, A2, A3.......A100 in my text file. I used :%s/A2/SAE/g successfully until A9 but when I use A1, all the A11 to A19 is changed. How do I specify the exact match here? (8 Replies)
Discussion started by: Kanja
8 Replies

2. Shell Programming and Scripting

vi substitution

Hello, I'm trying to do a substitution in vi. which adds a field for the year to a line. If the line doesnt include a year, it should still add a field (although empty) the fields are: Country:number:number:name(and sometimes year):place this is a desired in and output: Sweden:55:32:John... (2 Replies)
Discussion started by: drareeg
2 Replies

3. Shell Programming and Scripting

substitution help

How do i substitute ' with space in a file using sed or awk i am getting the following two scenarios 1) xyz'd with xyz d if i use sed 's/xyz\\\'d/xy z/g' it is taking ' after \ as closing expr for substitution 2) xyz';d with xyz d please advice (8 Replies)
Discussion started by: mad_man12
8 Replies

4. UNIX for Dummies Questions & Answers

vi editor substitution

Hi everyone, I am new to linux and practicing using vim editor. I am trying to substitute a word hi to hello and i can do this using by the following command s/hi/hello but this will only substitute only the first occurrence of hi and s/hi/hello/g will substitute every occurrence... (4 Replies)
Discussion started by: bonosungho
4 Replies

5. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

6. Solaris

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :Licen

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :License server is down (1 Reply)
Discussion started by: durgaprasadr13
1 Replies

7. Shell Programming and Scripting

set EDITOR=vi -> default editor not setting for cron tab

Hi All, I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by set EDITOR=vi it does not open a vi editor , rather it do as below..... ///////////////////////////////////////////////////// $ set... (6 Replies)
Discussion started by: aarora_98
6 Replies

8. UNIX for Dummies Questions & Answers

Pasting text in VI editor from a different editor

Hi, I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question. How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'? As i see, p & P options does work only within 'vi'. (10 Replies)
Discussion started by: harishmitty
10 Replies

9. UNIX for Dummies Questions & Answers

Need help in substitution!!!!

In a file I want to globally change a "|" charater by a new line character. I am using the command 1,$s/\|/??/g Can anybody say what should I put in place of ?? in the above command? (3 Replies)
Discussion started by: uLearner
3 Replies

10. Shell Programming and Scripting

substitution

I am trying to substituted a variable to a file using sed. However, the value of that variable is not being substituted. Here is an example of my code. lf=' ' v_whole="${1} ${2} ${3} $lf" cp ${IPPDIR}/ctl/fax_sub_text_a.${4}.${5}.txt... (1 Reply)
Discussion started by: supercbw
1 Replies
Login or Register to Ask a Question