LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 06-25-2014, 07:44 PM   #1
sam@
Member
 
Registered: Sep 2013
Posts: 31

Rep: Reputation: Disabled
Question delete a pattern


Hi

My file has patterns which look like

string1.1
string2.1
string 3.1
...
string 100.1....
and so on

I would like to replace them to
string1
string2
string3
string100

Basically removing .1 extension
I tried deleting the .1 pattern by using

sed /.1/d filename> newfile

But it deleted the entire line of string.

Please advise.
 
Old 06-25-2014, 08:20 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Hence you do not wish to delete, you wish to replace with nothing. Try the s/// construct instead
 
Old 06-25-2014, 09:52 PM   #3
sam@
Member
 
Registered: Sep 2013
Posts: 31

Original Poster
Rep: Reputation: Disabled
Thanks for inputs!

I did try another command :
Code:
 sed 's/.1//g' filename> newfile
But it did not give desired result.

Just to give an detail I have added detail of my original file.
My original file looks like
Code:
>string1.1
CCGCCGACCGCCCTCCCCCAACACGTAGGCCCCTTTCCCGAGCCTCTGCTTCATCTACACCATCGGTGACCCTCCGGGAGACACCCCCTTCCCACTTCCTCCCCCTCCGGCCACACTCCGGCGACGTCGCGTCGCCTTGGAGCTGCCCCCAACACTCTGTGCCCCGCTGGCTGCACCTTGGCTCCGCCGCACGTCGCATCTGCCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCATGCCCCCTCGCTTTTAGATATTTGGTGCACACCCCCTTTAAACTTATATAT
>string2.1
TCCCCCACCCATATGTTTGCCGACGCGCTCACACTTGTGTCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCAT
>string44.1
CCGCCGACCCCGCCGACCGCCCTCCCCCAACACGTAGGCCCCTTTCCCGAGCCTCTGCTTCATCTACACCATCGGTGACCCTCCGGGAGACACCCCCTTCCCACTTCCTCCCCCTCCGGCCACACTCCGGCGACGTCGCGTCGCCTTGGAGCTGCCCCCAACACTCTGTGCCCCGCTGGCTGCACCTTGGCTCCGCCGCACGTCGCATCTGCCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCATGCCCCCTCGCTTTTAGATATTTGGTGCACACCCCCTTTAAACTTATATAT
But when I used the above command it didnot quite give the required result.
It rectified all other strings but didnt work for the 1st string entry.

(It replaced string1.1 to just strin)
Part of my result :
Code:
>strin
CCGCCGACCGCCCTCCCCCAACACGTAGGCCCCTTTCCCGAGCCTCTGCTTCATCTACACCATCGGTGACCCTCCGGGAGACACCCCCTTCCCACTTCCTCCCCCTCCGGCCACACTCCGGCGACGTCGCGTCGCCTTGGAGCTGCCCCCAACACTCTGTGCCCCGCTGGCTGCACCTTGGCTCCGCCGCACGTCGCATCTGCCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCATGCCCCCTCGCTTTTAGATATTTGGTGCACACCCCCTTTAAACTTATATAT
>string2
TCCCCCACCCATATGTTTGCCGACGCGCTCACACTTGTGTCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCAT
>string44
CCGCCGACCCCGCCGACCGCCCTCCCCCAACACGTAGGCCCCTTTCCCGAGCCTCTGCTTCATCTACACCATCGGTGACCCTCCGGGAGACACCCCCTTCCCACTTCCTCCCCCTCCGGCCACACTCCGGCGACGTCGCGTCGCCTTGGAGCTGCCCCCAACACTCTGTGCCCCGCTGGCTGCACCTTGGCTCCGCCGCACGTCGCATCTGCCCGCTACGCTCCACAGCCACCCCGTCTCCAGCCTCGCCAACAACCATGCCCCCCGATCGCGCCTTGCTTGCCACCTCACTTGGCCCCGCAACGATCGGCCTCCATTTCCCCCTGTGTCGTCATGCCACTCGCCATGGCCGACACGGTTTCGGGATAGCTCTCCCCCCTATTGGAGCCTGGACATGGTCGGCTCACCATCGCATGCCCCCTCGCTTTTAGATATTTGGTGCACACCCCCTTTAAACTTATATAT
 
Old 06-26-2014, 02:04 AM   #4
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
edit

Last edited by kooru; 06-26-2014 at 02:06 AM.
 
Old 06-26-2014, 02:05 AM   #5
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
sorry for double post.

Try with:
Code:
sed 's/\.1//g'

Last edited by kooru; 06-26-2014 at 02:07 AM.
 
1 members found this post helpful.
Old 06-26-2014, 02:25 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
if it occurs only at the end of the line you can use the following:
sed 's/\.1$//'
 
Old 06-26-2014, 02:36 AM   #7
sam@
Member
 
Registered: Sep 2013
Posts: 31

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thanks for correcting!
 
  


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
Delete a line that ends with a pattern chetan_linux Programming 3 10-25-2013 11:10 AM
sed - delete everything before pattern? sliddjur Programming 11 11-10-2012 08:30 PM
how to delete lines according to a pattern in awk Massimo34 Programming 4 01-26-2012 04:19 PM
delete line containing a pattern!!! jacky29 Programming 7 12-28-2011 03:31 AM
How to delete the file using pattern match? nishanthhampali Programming 3 04-16-2008 01:50 PM


All times are GMT -5. The time now is 08:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration