03-03-2009
I found the unix command to be useful.
cat filename | sort | uniq -c | sort -nr
What if I am using a tab-delimited text file with multiple columns?
Example:
S100A16 hsa-miR-125a-3p S100A16 0.0011959 0.768059
PBXIP1 hsa-miR-125a-3p PBXIP1 0.0199898 0.700326
CYB5R3 hsa-miR-125a-3p CYB5R3 0.0081174 0.748953
BEST3 hsa-miR-125a-3p BEST3 0.00148927 0.756234
FAM101A hsa-miR-125a-3p FAM101A 0.0196212 0.783555
KIAA0195 hsa-miR-125a-3p KIAA0195 0.0019755 0.747427
LLGL2 hsa-miR-125a-3p LLGL2 0.0248212 0.876563
FBLN5 hsa-miR-125a-3p FBLN5 0.0162988 0.776446
IFITM3 hsa-miR-125a-3p IFITM3 0.00896808 0.478704
SSH3 hsa-miR-125a-3p SSH3 0.0301693 0.836054
EXTERNAL_NAME SEQ EXTERNAL_NAME p-value(1 vs. 2) Ratio(1 vs. 2)
EMILIN1 hsa-miR-369-5p EMILIN1 0.0254294 0.720094
ADD3 hsa-miR-369-5p ADD3 0.0184075 0.742096
AIFM2 hsa-miR-369-5p AIFM2 0.00646348 0.829228
GPT2 hsa-miR-369-5p GPT2 0.00473291 0.706895
and I want the output to read
10 hsa-miR-125a-3p
4 hsa-miR-369-5p
1 SEQ
Initially, I made a new file, composing only the column of interest, using perl (column 1 here), named it filenam_list; then applied the
cat filenam_list | sort | uniq -c | sort -nr > filename_counts
rm filenam_list
Is there a more efficient way of doing this? I'm sure there has to be. I repeated the procedure on 7 files and I have to it again.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi All,
is there a way to extract the line number of an occurrence using grep?
I know that with the -n option it prints out the line number as well.
I would like to assign the line number to a variable.
Thanks,
Sarah (5 Replies)
Discussion started by: f_o_555
5 Replies
2. UNIX for Dummies Questions & Answers
Hi all,
is there a simple way to obtain the line number of the i-th occurrence of a pattern?
I have
OCCURRENCE=`grep -io "${STRING_NAME}" ${1}-${8}${EXT}.out_bis| wc -l`
which tells me how many occurency I have. I would like to go through them and determine the line number and assign... (6 Replies)
Discussion started by: f_o_555
6 Replies
3. Shell Programming and Scripting
Alo
I have a file with a lot of addresses where I want to list unique addresses and the number of theirs occurrence.
I have this input file:
0011bd09 ea 01 0b 04 ea 01 0b 38-bd 11 00 98 15 cb 01 00 .......8........
0011bd09 ea 11 00 98 15 cb 01 00-00 00 00 d8 3d 8d 01 94 ... (5 Replies)
Discussion started by: chitech
5 Replies
4. Shell Programming and Scripting
Hi
I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)
Data in File.
<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies
5. Shell Programming and Scripting
Hi
I have the following file
ENST001 ENST002 4 4 4 88 9 9
ENST004 3 3 3 99 8 8
ENST009 ENST010 ENST006 8 8 8 77 8 8
Basically I want to count how many times ENST* is repeated in each line so the expected results is
2
1
3
Any suggestion please ? (4 Replies)
Discussion started by: fuad_
4 Replies
6. Shell Programming and Scripting
: i need a bash script to convert the displayed output
12
14
15
12
15
13
to
12 * 2 ,13 * 1,14*1,15*1
Thanks,
nevil (2 Replies)
Discussion started by: nevil
2 Replies
7. Shell Programming and Scripting
Hi,
I have a file which contained a set of numbers like
Col1 col2 col3 col4
1 sa 13 0
2 sb 14 0
3 sc 15 9
4 sd 16 -9
5 sd 20 -2
6 sd 20 4
Here in last column I need to count the zeros, positive values and negative values,
please help me to do that. (2 Replies)
Discussion started by: Shenbaga.d
2 Replies
8. Shell Programming and Scripting
My file contains like this on 10 th line
NM1*IL*1*
awk '/NM1/{print NR}' *.dat
output is 10
awk '/NM1*IL*1*/{print NR}' *.dat
output is Nothing
but im expecting 10 on second code as well . (4 Replies)
Discussion started by: Rajesh_us
4 Replies
9. Shell Programming and Scripting
Hi all,
I am looking for to filter out based on 7th character and list the number of occurrence based on the 7th character if p , d , o or m
1. if 7th character is p , Output should be: p_hosts = N
2. if 7th character is d , Output should be: d_hosts = N
3. if 7th character is o , Output... (10 Replies)
Discussion started by: rveri
10 Replies
10. Shell Programming and Scripting
Hello,
I'm looking for advice on how to optimize this bash script, currently i use the shotgun approach to avoid file io/buffering problems of forks trying to write simultaneously to the same file. i'd like to keep this as a fairly portable bash script rather than writing a C routine.
in a... (8 Replies)
Discussion started by: f77hack
8 Replies
LEARN ABOUT SUSE
pdl::char
Char(3) User Contributed Perl Documentation Char(3)
NAME
PDL::Char -- PDL subclass which allows reading and writing of fixed-length character strings as byte PDLs
SYNOPSIS
use PDL;
use PDL::Char;
my $pchar = PDL::Char->new( [['abc', 'def', 'ghi'],['jkl', 'mno', 'pqr']] );
$pchar->setstr(1,0,'foo');
print $pchar; # 'string' bound to "", perl stringify function
# Prints:
# [
# ['abc' 'foo' 'ghi']
# ['jkl' 'mno' 'pqr']
# ]
print $pchar->atstr(2,0);
# Prints:
# ghi
DESCRIPTION
This subclass of PDL allows one to manipulate PDLs of 'byte' type as if they were made of fixed length strings, not just numbers.
This type of behavior is useful when you want to work with charactar grids. The indexing is done on a string level and not a character
level for the 'setstr' and 'atstr' commands.
This module is in particular useful for writing NetCDF files that include character data using the PDL::NetCDF module.
FUNCTIONS
new
Function to create a byte PDL from a string, list of strings, list of list of strings, etc.
# create a new PDL::Char from a perl array of strings
$strpdl = PDL::Char->new( ['abc', 'def', 'ghij'] );
# Convert a PDL of type 'byte' to a PDL::Char
$strpdl1 = PDL::Char->new (sequence (byte, 4, 5)+99);
$pdlchar3d = PDL::Char->new([['abc','def','ghi'],['jkl', 'mno', 'pqr']]);
string
Function to print a character PDL (created by 'char') in a pretty format.
$char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
print $char; # 'string' bound to "", perl stringify function
# Prints:
# [
# ['abc' 'def' 'ghi']
# ['jkl' 'mno' 'pqr']
# ]
# 'string' is overloaded to the "" operator, so:
# print $char;
# should have the same effect.
setstr
Function to set one string value in a character PDL. The input position is the position of the string, not a character in the string. The
first dimension is assumed to be the length of the string.
The input string will be null-padded if the string is shorter than the first dimension of the PDL. It will be truncated if it is longer.
$char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
$char->setstr(0,1, 'foobar');
print $char; # 'string' bound to "", perl stringify function
# Prints:
# [
# ['abc' 'def' 'ghi']
# ['foo' 'mno' 'pqr']
# ]
$char->setstr(2,1, 'f');
print $char; # 'string' bound to "", perl stringify function
# Prints:
# [
# ['abc' 'def' 'ghi']
# ['foo' 'mno' 'f'] -> note that this 'f' is stored "f "
# ]
atstr
Function to fetch one string value from a PDL::Char type PDL, given a position within the PDL. The input position of the string, not a
character in the string. The length of the input string is the implied first dimension.
$char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
print $char->atstr(0,1);
# Prints:
# jkl
perl v5.12.1 2009-10-17 Char(3)