Repeating Substitution Command on VI


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Repeating Substitution Command on VI
# 1  
Old 09-27-2010
Repeating Substitution Command on VI

Hello Folks,
how to write a command on vi that allow to repeat last substitution command?

Here what I want to do :

Code:
1
2
3
1
2
3
1
2
3
:.,+2s/\n/ /

And I obtain :
Code:
1 2 3
1
2
3
1
2
3

I want a command like
Code:
:%[.,+1]s/\n/ /

(that doesn't work)

to have just with a command the exit :
Code:
1 2 3
1 2 3
1 2 3

Is it possible?

tks you all
# 2  
Old 09-27-2010
Code:
:%!paste -d\  - - -

# 3  
Old 09-27-2010
Wonderfull!!!
Can you explain please ?
:P
# 4  
Old 09-27-2010
The above command just invokes the external program paste to edit the vi buffer,
it's like:

Code:
paste -d\  - - - < your_file

If I'm not missing something, this command should work without any external program:

Code:
:%g/^/.,+1s/\n/ /

[adjust the number to taste]
# 5  
Old 09-27-2010
The last one is exactly what I was looking for.
Grazie Mille!!!
# 6  
Old 09-27-2010
Prego Smilie

You're welcome!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regarding command substitution

Oracle Linux 5.6, 64-bit Given the following snippet wrkvar=`sqlplus -s / as sysdba <<EOF set echo off feedback off head off trimsp on select count(*) from v\$parameter where name in ('db_file_name_convert','log_file_name_convert') and value is not null; EOF` echo wrkvar=$wrkvarProduces... (2 Replies)
Discussion started by: edstevens
2 Replies

2. Shell Programming and Scripting

awk and or sed command to sum the value in repeating tags in a XML

I have a XML in which <Amt Ccy="EUR">3.1</Amt> tag repeats. This is under another tag <Main>. I need to sum all the values of <Amt Ccy=""> (Ccy may vary) coming under <Main> using awk and or sed command. can some help? Sample looks like below <root> <Main> ... (6 Replies)
Discussion started by: bk_12345
6 Replies

3. 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

4. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

5. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

6. UNIX for Advanced & Expert Users

Repeat output of last command w/o repeating last command

Is there a way to repeat the output of the last command for filtering without running the command again? All I could think of was to copy all the data to a text file and process it that way, is there another way? Like say I want to grep server.server.lan from a dtrace that was pages long after I... (5 Replies)
Discussion started by: glev2005
5 Replies

7. Shell Programming and Scripting

Repeating awk command

Hi all, I have an awk command that needs to be ran multiple times in a script on one file containing lots of fields of data. The file look like this (the numbers are made up): 1234 2222 2223 2222 123 2223 3333 2323 3333 3321 3344 4444 The... (2 Replies)
Discussion started by: nistleloy
2 Replies

8. UNIX for Advanced & Expert Users

unix script for repeating a command with a variable

Hi need urgent help , for creating unix script . To collect system name,This is command i want to execute n (integer) no. of times for for a differnt IP addresses .IP is variable in every execution. Other string & collecter name is constant . snmpGet %IP% sysName.0 -c <string> -S <datacollecter... (2 Replies)
Discussion started by: langdatyagi
2 Replies

9. UNIX for Dummies Questions & Answers

repeating previous argument on command line?

Hi, is there a way in bash--or any other shell--to repeat the preceding argument on the command line? E.g., let's say I want to rename the file "/var/www/conf/httpd.conf" to "/var/www/conf/httpd.conf.bak". I want to be able to type mv /var/www/conf/httpd.conf, and then press a command key that... (6 Replies)
Discussion started by: hadarot
6 Replies

10. Shell Programming and Scripting

Substitution of last command

"Is there any substituation of last command or script syntax which can be used as a user. As far I know the "last" command is being used to display information about previous logins. A member of adm group or the user adm can execute it only. Thanks in advance for your usual help. Ghazi (6 Replies)
Discussion started by: ghazi
6 Replies
Login or Register to Ask a Question