LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-29-2013, 05:48 PM   #1
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Rep: Reputation: 15
Vim command to move certain words with a pattern to a new text file


Does anyone know the command to extract only the words with a certain symbol in front of them from a text file. I know the command should look something like this: %s/\v(.*)(*@,\d)(.*)/\2 if I wanted to extract words only having @ in front of them. However, I’m getting an error “E59: invalid character after @" What is going wrong?
 
Old 09-29-2013, 06:07 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I am not sure your question is specific enough (better definition of "move" and "in front of"), and your "command" (regular expression) does not seem to make much sense, but I suspect that sed or awk would be more what you are looking for.

It would help f you could be a little more exact in what you need, and maybe give an example or two of what you want to extract and how it should appear in the new file.
 
Old 09-29-2013, 08:20 PM   #3
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Original Poster
Rep: Reputation: 15
I'm trying to do this in Vim, which I neglected to directly mention in the post. Seems like it should be simple. What do you think is going wrong? So if the orignal file was a 400 page text file with 20 email addresses in it on random pages, and I only wanted to extract the 20 email addresses. How can I get Vim to just spit out the email addresses from that text file?

Thanks

Last edited by trox; 09-29-2013 at 08:25 PM.
 
Old 09-30-2013, 08:46 AM   #4
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by astrogeek View Post
I am not sure your question is specific enough (better definition of "move" and "in front of"), and your "command" (regular expression) does not seem to make much sense, but I suspect that sed or awk would be more what you are looking for.

It would help f you could be a little more exact in what you need, and maybe give an example or two of what you want to extract and how it should appear in the new file.
You were right! awk did a beautiful job of separating everything into a list in the terminal. I copied that list into a spreadsheet and filtered it. I will be looking into more of what awk can do. What a powerful little program! Thank you!
 
Old 10-19-2021, 05:19 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by trox View Post
I know the command should look something like this: %s/\v(.*)(@,\d)(.*)/\2 if I wanted to extract words only having @ in front of them. However, I’m getting an error “E59: invalid character after @" What is going wrong?
An old thread and solved as well, but at least, I can say what was wrong with the pattern. In Vim regular expressions, \v means very magic, it allows using any non-alphanumeric RE metacharacters without preceding backslash. Non-alphanumeric is the key word here. Not only parentheses and braces, but really anything and everything: e.g. < and > instead of \< and \> for word boundaries, etc.

Now, \@ happens to be a metacharacter for lookarounds in Vim regular expressions. So, after \v Vim treats a bare @ as such metacharacter, but doesn't see the correct syntax for it: e.g. @= for positive lookahead, @! for negative lookahead, and so on. Thus, the error message.

BTW, Vim error codes are tags in Vim help. To find out what this error is about, type :h e59 from inside Vim.
 
  


Reply

Tags
data, extract, move, pattern, vim



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
May I use a command to select some words from a text and write it to another ? anome Linux - Software 16 09-26-2012 07:13 AM
[SOLVED] How to move-in directory having two words using cd command? gabytf Linux - Software 4 11-04-2011 07:45 AM
Command to delete words out of a text file. Dazamondo Linux - Newbie 13 06-30-2009 10:48 AM
vim: search pattern / replace with file naflan Programming 5 01-07-2006 03:16 PM
Command to select and move mutiple files from list in text file steve.paris Linux - Newbie 11 11-27-2005 12:44 PM

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

All times are GMT -5. The time now is 08:20 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
Open Source Consulting | Domain Registration