There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop lcd malware memory modem monitor motherboard network printer problem ram registry router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Solved: looking help on VI search and replace

Reply  
Thread Tools
jlaanep's Avatar
Junior Member with 4 posts.
 
Join Date: Oct 2008
15-Oct-2008, 02:21 PM #1
Solved: looking help on VI search and replace
Hello,

I'm attempting to manipulate a large data file. What I'm attempting to do is find a bracket '(' then on the same line find a character followed by a ',' ([A-Za-z],) then on the same line find a space then delete the space and everything after it on that line.

So far what I've been able to come up with results in an error (E488: Triailing Characters). I'm not sure what I'm doing wrong as my vi and reg expressions are basic at best. If someone could manipulate what I have or offer some suggestions that would be great.

Here's what I've come up with (both result in the same error):

s/(/;/[A-Za-z],/;/\ //

s/\(/;/[A-Za-z]\,/;/\ //


TIA
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
15-Oct-2008, 06:52 PM #2
Hi jlaanep,

I would not use vi for this problem, but nawk which is a variant of awk since it contains substring functions that can simplify what you are trying to do - i.e. each line you are interested in must contain a '(', followed by some characters and a ',' followed by zero or more characters and a space - at which time you delete from the position of the space to the end of the line.

Try to search for an awk, gawk or nawk tutorial on the Internet, and learn how to invoke an awk program in a file, as your processing requirements are more than just simple enough to use vi and regular expressions.

-- Tom

P.S. Reference: The AWK Programming Language by Aho, Kernighan, and Weinberger, Addison-Wesley Series in Computer Science
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
TerryNet's Avatar
Computer Specs
Moderator with 48,385 posts.
 
Join Date: Mar 2005
Location: Ottawa, IL
Experience: Intermediate to Advanced
15-Oct-2008, 09:23 PM #3
:g/\(([A-Za-z],[^ ]*\) .*/s//\1

colon g slash backslash leftparen leftparen leftbracket A-Za-z rightbracket comma leftbracket ^ space rightbracket asterisk backslash rightparen space period asterisk slash s slash slash backslash 1
jlaanep's Avatar
Junior Member with 4 posts.
 
Join Date: Oct 2008
16-Oct-2008, 04:34 AM #4
Thanks to the both of you! I'll look up both of these tomorrow (or I guess today now) when I get into work!

I'll let you know how it goes and the solution I found.

jlaanep.
TerryNet's Avatar
Computer Specs
Moderator with 48,385 posts.
 
Join Date: Mar 2005
Location: Ottawa, IL
Experience: Intermediate to Advanced
17-Oct-2008, 09:56 PM #5
I must admit to disappointment that we haven't heard back from you. If I misunderstood your requirements I would be happy to try to make changes.
jlaanep's Avatar
Junior Member with 4 posts.
 
Join Date: Oct 2008
22-Oct-2008, 09:04 AM #6
Hello again guys!

Sorry about not responding fast but I had a server down and haven't had a chance to look at the search/replace until this morning.

Terry, your search/replace string did the trick, thanks again!

JL.
TerryNet's Avatar
Computer Specs
Moderator with 48,385 posts.
 
Join Date: Mar 2005
Location: Ottawa, IL
Experience: Intermediate to Advanced
22-Oct-2008, 02:17 PM #7
You're welcome. Glad it worked for you. You can mark this "Solved" using the button at the upper left of your first post.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:10 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.