LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-18-2005, 01:16 PM   #1
tragos
LQ Newbie
 
Registered: Oct 2004
Location: Hersbruck, Germany
Distribution: Kubuntu
Posts: 3

Rep: Reputation: 0
vim: Piping through multiple external commands


Is there any way to pipe through multiple external commands in vim?

For example, I would like to sort all lines in the buffer and then run unique on them.

Example of what I would like to do from the : prompt in normal mode (does not work as written):

:% !sort | uniq

The problem I am running into is that vim uses the pipe symbol to run consecutive commands.

Writing scripts or consecutive commands is possible, but I would like to avoid that.
 
Old 03-19-2005, 06:26 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Hi,

I probably misunderstand the question, but if I copy/paste the above command (:% !sort | uniq) into a vim session it works as expected (all lines are sorted uniqely).

Tried on an old suse (8.2) and LFS, both work. I don't have RH.

Please tell us a bit more about what's going wrong.
 
Old 03-19-2005, 02:09 PM   #3
tragos
LQ Newbie
 
Registered: Oct 2004
Location: Hersbruck, Germany
Distribution: Kubuntu
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your response.

Now, I can't repro it either, I must have had an extra % on the command line, though with a command that simple I find that hard to believe.

My original problem was that I was trying to filter text through awk, resulting in an error (which I should have written down) that I could repro with the more simple command. After reviewing again, it was the % in the awk placeholder text that was originally causing the problem, with vim complaining about an "Empty file name".

Example (that now works):
:% !sort | uniq | awk '{printf("X\%s\n", $0);}'

Even though the printf format string is in single quotes, the % must be escaped as \%. It looks like vim uses a very different command text parser than bash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with commands and piping basselstine Linux - General 1 10-02-2005 10:43 PM
multiple files in VIM james.farrow Linux - Newbie 3 07-09-2004 06:46 AM
Multiple commands with exec! dtheorem Linux - General 1 03-14-2004 04:46 PM
piping commands john8675309 Linux - Software 3 12-06-2003 08:42 AM
vim commands in perl JohanLingen Programming 5 01-08-2003 05:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration