LinuxQuestions.org
Help answer threads with 0 replies.
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 10-13-2015, 12:53 AM   #1
Syeda Sumayya
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
Removing a character at specific position in a column


Hi,

I have a file like this (about 8 columns in total, this being the 2nd column)

Code:

gi_49482297_ref_YP_039521.1_
gi_49482297_ref_YP_039521.1_
gi_49482315_ref_YP_039539.1_
gi_49482315_ref_YP_039539.1_


I want to remove the _ at the end of the line.
And at later stages I would want to replace the _ with another character perhaps.

how can I do it using awk or sed?

Any help would be highly appreciated.

Last edited by Syeda Sumayya; 10-13-2015 at 12:58 AM.
 
Old 10-13-2015, 01:02 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Welcome to LQ

Here's something that does only that, just as a ptr towards creating your own soln
Code:
echo 'gi_49482315_ref_YP_039539.1_'|sed  -E 's/_$//'
gi_49482315_ref_YP_039539.1
If eg the cols are separated by exactly one space, then you could use the 'cut' cmd to pull this out for processing.

Really we'd like to see

a) some whole recs so we can see the actual issue
b) what code have you tried so far - we prefer to help you solve this, rather than just handout solns
 
Old 10-13-2015, 01:55 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As chrism01 has said, this really is not enough information, but based on the loose details, you could use awk like so:
Code:
awk 'sub(/_$/,"",$2)' file
 
  


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
[SOLVED] awk character position matching dazdaz Programming 13 04-23-2011 01:19 AM
sed replacing a specific character with a specific number ieatbunnies Linux - Newbie 2 11-04-2010 10:14 AM
Script to get position #s of first and last A-Z character on certain lines? kmkocot Programming 10 10-07-2010 09:21 AM
replace specific character after specific line by awk Syed Tarique Moin Programming 2 07-19-2010 01:47 PM
Inspected a character on a particular position in a word kushalkoolwal Programming 10 07-03-2008 08:37 PM

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

All times are GMT -5. The time now is 09:42 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
Open Source Consulting | Domain Registration