LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-14-2009, 02:12 PM   #1
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Rep: Reputation: 30
How do I remove everything after a certain character in text files?


I have a text file with a few thousand lines in the format:

Code:
abcdef*ghijk*lmno
pqrs*tuv
wx*y*z
etc.

What I want to do is, get rid of everything after the SECOND asterik (the *) in each line (including the asterik). So for the example above, it would look like this after the editing:

Code:
abcdef*ghijk
pqrs*tuv
wx*y
How can I do this?
 
Old 01-14-2009, 02:45 PM   #2
nflenz
Member
 
Registered: Feb 2006
Distribution: CRUX 2.4
Posts: 96

Rep: Reputation: 18
I'm going to assume you are using vi like you were in your other question.

Code:
:g/\*.*\*/s/\*[^\*]*$/\*/
That is a pretty ugly regular expression, but it should work
 
Old 01-14-2009, 02:50 PM   #3
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Original Poster
Rep: Reputation: 30
This is what it says in vi:
Code:
E486: Pattern not found: \*.*\*
 
Old 01-14-2009, 03:15 PM   #4
nflenz
Member
 
Registered: Feb 2006
Distribution: CRUX 2.4
Posts: 96

Rep: Reputation: 18
Hmm. I don't see anything wrong with it. The first regular expression (the one producing the error) is the same one I provided you in the other post, so it should work.

It looks like it just can't find the pattern. Search through the file and verify that there are lines containing two asterisks.

I do have one correction to make. I originally wrote the command to retain the second asterisk, but after reading your post a second time I see you don't want it. Remove the final "\*" to fix this.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove last character from file/string linuxchump Programming 34 06-08-2009 05:01 AM
How to store text(strings) in a 2D character array reading from a text file(C++) bewidankit Programming 3 02-14-2008 08:08 AM
Remove rightmost character from bash gn00kie Programming 9 01-29-2008 01:08 AM
remove the 'd' character from the end of string powah Programming 6 11-08-2007 08:00 AM
Can VI Do This?? Delete before a character in text - Maybe advanced. tbeehler Linux - Software 9 05-07-2007 06:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:11 AM.

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