LinuxQuestions.org
Help answer threads with 0 replies.
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 10-02-2015, 02:50 PM   #1
sam@
Member
 
Registered: Sep 2013
Posts: 31

Rep: Reputation: Disabled
SELECTIVE REPLACE error


Hi
My input file looks like this:


Code:
WPMG3215  NFM   erine    511   750   .       -       .       Distance=NFM.RT.WPMG3215.2;Name=erine.WPMG3215.1
WPMG3215  NFM   NFS   511   700   .       -       .       Distance=NFM.arch.WPMG3215.2;Description=NFM.RT.WPMG3215.2
WPMG3215  NFM   NGS    513   654   .       -       .       Distance=NFM.arch.WPMG3215.12.NGS;Description=NFM.arch.WPMG3215.34
WPMG3215  NFM   short  543   618   .       -       .       Description=NFM.arch.WPMG3215.21
WPMG3215  NFM   long    618   719   .       -       .       Distance=NFM.arch.WPMG3215.32.NGS2;Description=NFM.arch.WPMG3215.31
WPMG1111  NFM   erine    800   900   .       -       .       Distance=NFM.RT.WPMG1111.23;Name=erine.WPMG1111.23
WPMG1111  NFM   NFS    811   900   .       +       .       Distance=NFM.arch.WPMG1111.13;Description=NFM.RT.WPMG1111.13;Name=NFS.WPMG1111.13
WPMG1111  NFM   NGS    832   833   .       -       .       Distance=NFM.arch.WPMG1111.8.NGS2;Description=NFM.arch.WPMG1111.6
WPMG1111  NFM   long  854   851   .       +       .       Description=NFM.arch.WPMG1111.32

My required output is
Code:
Para3215  NFM   erine    511   750   .       -       .       Distance=NFM.RT.WPMG3215.2;Name=erine.WPMG3215.1
Para3215  NFM   NFS   511   700   .       -       .       Distance=NFM.arch.WPMG3215.2;Description=NFM.RT.WPMG3215.2
Para3215  NFM   NGS    513   654   .       -       .       Distance=NFM.arch.WPMG3215.12.NGS;Description=NFM.arch.WPMG3215.34
Para3215  NFM   short  543   618   .       -       .       Description=NFM.arch.WPMG3215.21
Para3215  NFM   long    618   719   .       -       .       Distance=NFM.arch.WPMG3215.32.NGS2;Description=NFM.arch.WPMG3215.31
Para1111  NFM   erine    800   900   .       -       .       Distance=NFM.RT.WPMG1111.23;Name=erine.WPMG1111.23
Para1111  NFM   NFS    811   900   .       +       .       Distance=NFM.arch.WPMG1111.13;Description=NFM.RT.WPMG1111.13;Name=NFS.WPMG1111.13
Para1111  NFM   NGS    832   833   .       -       .       Distance=NFM.arch.WPMG1111.8.NGS2;Description=NFM.arch.WPMG1111.6
Para1111  NFM   long  854   851   .       +       .       Description=NFM.arch.WPMG1111.32
I used the following command to only replace the first tab entries
Code:
sed 's/^WPMG\t/Para\t/' filename>sortedfile
But it didnt work.

How should I update only the first tab entries. I dontwant to affect other tab entries having WPMG.
 
Old 10-02-2015, 02:51 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
Is this it?

Code:
sed 's/^WPMG/Para/' filename > sortedfile
Your original sed string is looking for 'WPMG<tabspace>' because of the \t

Last edited by szboardstretcher; 10-02-2015 at 02:53 PM.
 
Old 10-02-2015, 03:37 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
Also, and trying not to be too picky, but you have called the new file 'sortedfile', yet nothing in the sed would affect the current sorted-ness of the original file
 
  


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
"Badly placed ()'s." error while trying to do selective rm -rf technizia Linux - Newbie 5 08-19-2014 11:00 PM
Selective replace help sonia102d Linux - Newbie 8 01-27-2013 12:28 AM
boot error after replace video cart Benny.W Linux - Hardware 4 10-22-2012 10:06 AM
How can i replace 503 error page in Apache? ppawcio Linux - Server 3 03-20-2010 11:18 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 02:04 AM

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

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