Removing last ten characters from a column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Removing last ten characters from a column
# 1  
Old 03-23-2009
Removing last ten characters from a column

I have a file that looks like this:

hsa-miR-517b-4373244 0 4.116
hsa-miR-886-5p-4395304 1.173 1.95
hsa-miR-551b-4380945 1.62 1.722
hsa-miR-886-3p-4395305 1.479 3.074
hsa-miR-125a-3p-4395310 1.246 2.697
hsa-miR-874-4395379 1.985 1.721

I want it too look like this:

hsa-miR-517b 0 4.116
hsa-miR-886-5p 1.173 1.95
hsa-miR-551b 1.62 1.722
hsa-miR-886-3p 1.479 3.074
hsa-miR-125a-3p 1.246 2.697
hsa-miR-874 1.985 1.721

...etc.

Any suggestions using unix and / or perl commands?
~much appreciated in advance.
# 2  
Old 03-23-2009
try this simple sed command
Code:
sed 's/\(.*\)\(-.*\)\( [0-9].* \)\(.*\)/\1\3\4/g' filename

# 3  
Old 03-23-2009
Another approach:

Code:
sed 's/\(.*\)-[^ ]*\(.*\)/\1\2/' file

Regards
# 4  
Old 03-23-2009
Thank you very much for replying. Neither of those solutions worked.

I think that all that happened was it removed the last value from the last column (in perl, Column 2). The file has 3 columns (0, 1, 2); the first column is a name and the other two are values (measurements). I want to import these files into a graphing program. The name, though, has extraneous information in it (ie: the last ten characters are catalogue numbers).
# 5  
Old 03-23-2009
Quote:
Originally Posted by e3r1ck_ETT
Thank you very much for replying. Neither of those solutions worked.

I think that all that happened was it removed the last value from the last column (in perl, Column 2). The file has 3 columns (0, 1, 2); the first column is a name and the other two are values (measurements). I want to import these files into a graphing program. The name, though, has extraneous information in it (ie: the last ten characters are catalogue numbers).
the kind of the i/p and o/p you provided can be obtained by both of these commands so if your req changed please put the correct i/p and o/p
# 6  
Old 03-23-2009
It should work, this is my output:

Code:
$ cat file
hsa-miR-517b-4373244 0 4.116
hsa-miR-886-5p-4395304 1.173 1.95
hsa-miR-551b-4380945 1.62 1.722
hsa-miR-886-3p-4395305 1.479 3.074
hsa-miR-125a-3p-4395310 1.246 2.697
hsa-miR-874-4395379 1.985 1.721
$
$ sed 's/\(.*\)-[^ ]*\(.*\)/\1\2/' file
hsa-miR-517b 0 4.116
hsa-miR-886-5p 1.173 1.95
hsa-miR-551b 1.62 1.722
hsa-miR-886-3p 1.479 3.074
hsa-miR-125a-3p 1.246 2.697
hsa-miR-874 1.985 1.721
$

Regards
# 7  
Old 03-23-2009
Maybe I am misunderstanding how to do something. I am operating in the "Terminal" of a Mac OS. I navigated to the appropriate dir.

My input file is a tab-delimited text file that looks like above.

The command I entered was this:

Quote:
$ sed 's/\(.*\)-[^ ]*\(.*\)/\1\2/' Controlvs-HIV-HIVMDD-HIVE-2_KMcluster_output.txt > Controlvs-HIV-HIVMDD-HIVE-2_KMcluster_output_trimmed.txt
The output file looks mostly the same except at the very end, where the 3rd column is truncated from the final row.

IE:
Last 3 rows of input:
Quote:
hsa-miR-518e-4395506 -1.308 -3.079
hsa-miR-369-3p-4373032 1.612 -4.058
hsa-miR-216b-4395437 3.878 -4.009
And last 3 rows of output:
Quote:
hsa-miR-518e-4395506 -1.308 -3.079
hsa-miR-369-3p-4373032 1.612 -4.058
hsa-miR-216b-4395437 3.878
Thanks again.
-E
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use regex on particular column (Removing comma from particular column)?

Hi, I have pipe separated file which contains some data having comma(,) in it. I want to remove the comma(,) only from particular column without changing data in other columns. Below is the sample data file, I want to remove the comma(,) only from 5th column. $ cat file1 ABC | DEF, HIJ|... (6 Replies)
Discussion started by: Prathmesh
6 Replies

2. Shell Programming and Scripting

Removing last and first characters in a file

bash-3.00$ cat temp.txt ./a/REA01/ces1/apps/ces_ces1_init3_aa.ear/ces.war/WEB-INF/classes/reds/common/environment.properties ./a/REA01/ces1/apps/ces_ces1_init3_aa.ear/commonproperties/hi/HostIntegration.properties... (9 Replies)
Discussion started by: bhas85
9 Replies

3. UNIX for Dummies Questions & Answers

Removing trailing x'0A' characters.

I am trying to remove trailing carriage return (x'0a') from a source program. What is a good way to do this for the whole file? TIA (4 Replies)
Discussion started by: wbport
4 Replies

4. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

5. Shell Programming and Scripting

Removing ^M characters from a file

Hi, I want to removing ^M characters from a file and combine the line with the next line. ex: issue i have: ABC^M^M DEF solution i need: ABCDEF I found that you by using the following command you can remove new line characters. tr -d '\r' < infile.csv > outfile.csv still... (10 Replies)
Discussion started by: mwrg
10 Replies

6. UNIX for Dummies Questions & Answers

Removing ^M characters

hi I have a perl script conv.pl. when i execute this file and direct i to log file I see lots of ^M characters in the log file. There is no ^M in conv.pl file. Log file is generated only after conv.pl is executed. Please help as how to get rid of these. This conv.pl is going to get schduled... (5 Replies)
Discussion started by: infyanurag
5 Replies

7. UNIX for Advanced & Expert Users

Removing ^M characters

hi I have a perl script conv.pl. when i execute this file and direct i to log file I see lots of ^M characters in the log file. There is no ^M in conv.pl file. Log file is generated only after conv.pl is executed. Please help as how to get rid of these. This conv.pl is going to get schduled... (0 Replies)
Discussion started by: infyanurag
0 Replies

8. UNIX for Dummies Questions & Answers

removing characters

Hi all, Any help on how to do the following? :eek: I have an infile as follows: _thisishowyouwritehelloworld _thisisalsohowyouwritehelloworld2 I want to delete the characters from "_" to "how" and be left with: youwritehelloworld youwritehelloworld2 I am able to do delete from a... (2 Replies)
Discussion started by: dr_sabz
2 Replies

9. HP-UX

Removing ^D and ^H characters

Hi, I have a very huge file and it contains some unprintable characters like ^H and ^D. If I try to remove using cat test1.ser| tr -d '\136 110'>newfile1 it is only removing ^and all spaces in the file. How can I remove these characters (^D ^H) and keep my spaces as it is? Thanks &... (1 Reply)
Discussion started by: arsheshadri
1 Replies

10. Shell Programming and Scripting

Help with removing characters like ^M

I have few files in unix which are in dos format. While I am copying these files, ^M, ^@, etc characters are being generated. I tried dos2unix command in Linux and it doesn't work. I tried sed to remove these characters but they won't go. I came to about this 'tr' command and tried to use it... (16 Replies)
Discussion started by: chiru_h
16 Replies
Login or Register to Ask a Question