LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-04-2013, 01:55 PM   #1
Drigo
Member
 
Registered: May 2009
Posts: 111

Rep: Reputation: 17
Angry Replace character in between?? gedit??


Lets say I have a file with the following text:


index="1" x="59" y="12" z="44"> Middle cerebellar peduncle
index="2" x="89" y="97" z="40">Pontine
index="3" x="93" y="152" z="77">Genu of co
index="4" x="95" y="100" z="97">Body
index="5" x="85" y="89" z="88">Spleniu
index="6" x="89" y="116" z="88">For
.
.
.


**I want to remove all the character between "x" and ">". Usually I use gedit to do so but I dont know how to replace the character to look like this:

index="1" Middle cerebellar peduncle
index="2" Pontine
index="3" Genu of co
index="4" Body
index="5" Spleniu
index="6" For
.
.
.
 
Old 04-04-2013, 02:02 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
If there's a whitespace between '>' and word next to it in all lines, you can simply use awk, as:
Code:
~$ awk 'BEGIN{FS=" "}; {print $1,$5,$6,$7}' infile
 
Old 04-04-2013, 03:29 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by shivaa View Post
If there's a whitespace between '>' and word next to it in all lines ...
You can force that by replacing '>' with a blank, thusly ...
Code:
awk '{sub(/>/," "); print $1,$5,$6,$7}' $InFile
Daniel B. Martin
 
Old 04-04-2013, 03:32 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Consider a sed solution ...
Code:
sed -r 's/(" )(.*>)/\1/' $InFile
Daniel B. Martin

Last edited by danielbmartin; 04-04-2013 at 03:41 PM. Reason: Improved code
 
Old 04-04-2013, 03:43 PM   #5
Drigo
Member
 
Registered: May 2009
Posts: 111

Original Poster
Rep: Reputation: 17
Thanks!

I was looking for a command like:
$replace <whatever is in between "x" and ">" with " " > kind of script/command line other than just awk or sed... :/
 
Old 04-04-2013, 03:54 PM   #6
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by Drigo View Post
... other than just awk or sed... :/
If you don't like awk or sed, look at this ...
Code:
cut -d'"' -f1-2,9- $InFile |tr '>' ' '
Daniel B. Martin
 
Old 04-04-2013, 06:26 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
If you do not wish to use a specific tool, you will need to let us know what you do wish to use?

As it is, the 2 you are discounting would be the general go to for something of this nature.
 
Old 04-04-2013, 06:37 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In vi / vim
Code:
:s/ x=.*>//
 
  


Reply



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
Find and Replace character/special character from the file MyRelam Red Hat 8 05-21-2012 12:52 AM
[SOLVED] Gedit help on Replace. LAPIII Linux - Newbie 3 04-25-2011 07:25 PM
Gedit has not been able to detect the character encoding on Ubuntu? Ubuntonian Linux - Software 13 11-25-2010 08:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:22 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