LinuxQuestions.org
Review your favorite Linux distribution.
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, 02:55 PM   #1
Drigo
Member
 
Registered: Jun 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, 03: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, 04:29 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,606

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
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, 04:32 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,606

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

Last edited by danielbmartin; 04-04-2013 at 04:41 PM. Reason: Improved code
 
Old 04-04-2013, 04:43 PM   #5
Drigo
Member
 
Registered: Jun 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, 04:54 PM   #6
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,606

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
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, 07:26 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,565

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
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, 07:37 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

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


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

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

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