2010年10月3日 星期日

Edit command

--------------------------------------------------------
1. cut
sample
{{{
hostname | cut -d “.” -f 1
}}}
represent using the dot to seperate, and f mean print filed 1

--------------------------------------------------------
2. list direction
{{{
ls -d */
}}}

--------------------------------------------------------
3. awk
Using the awk to list the filed 1 (start 1) value is 6
{{{
[Andy@localhost summary]$ awk '$1==6' eles | less
}}}

---------------------------------------------------------
4. uniq can reduce the same element in one element.
Becarefully: u need sorting before show single line data, because uniq using the delete method in succive
{{{
file name.dat
[
Andy
Merry
David
Andy
]
[Andy@localhost pracice]$ sort Field.data | uniq -c
2 Andy
1 David
1 Marry

}}}

--------------------------------------------------
sed

* list content
{{{
sed -n '4,$p' 454AllContigs_change.fna.out | less
}}}

* Insert line 1 before as the tilte
{{{
sed -i ''1i tiltle" file
}}}

Substation command
* remove many spaces to a tab
sed 's/\s\s*/\t/g' mean one space and many space to a tab
{{{
[Andy@localhost TestResult]$ cat simpleData
rnd-3_family-30 1 1066 1066 1066.00 1066

cat simpleData | sed 's/\s\s*/\t/g' > ~/Desktop/tmp/
}}}

* change the (number*) to number, and not change the (charcate*) to (character),
becareful the group operator is \(\) and the get is \1
{{{
sed 's/(\([0-9][0-9]*\))/\1/g'
}}}

* list the email
{{{
cat tmp | sed 's/.*<\([a-z.0-9][a-z.0-9]*@..*\)>.*/\1/' | awk '{ print $1","}'
}}}

* sed remove control A
{{{
less Parsed_Blastp_ORF_FGSH_ASP.txt | sed 's/\cA/\t/'
}}}

*sed find the length
{{{
>contig00005 gene=isogroup00001 length=1854
>contig00006 gene=isogroup00001 length=715
>contig00007 gene=isogroup00001 length=773

[Andy@blast2 newbler26_CPU1_cDNA]$ cat 454Isotigs.fna.header | sed 's/.*length=\([0-9]*\).*/\1/'
}}}


Notice:
1. Sed no + quality
2. sed group operation is specail using the \( character \), and get using \1 ... \n
perl is () and $1... $n

Reference:
http://www.panix.com/~elflord/unix/sed.html
------------------------------------------------
awk
final column is RNF
{{{
awk '{print $NF}' consensi.fa.classified.LTR.lengthTable > consensi.fa.classified.LTR.lengthTable.OnlyLength
}}}

------------------------------------------------
split
can split the content of file like lines or size
split -l 1000 file sffix
{{{
split -l 1000 sfile
}}}

--------------------------------------------------
problem The windown file have \r\n generate ^M symbol
we need remove it on comand
{{
head -n 3 AUG.txt | tr -d '^M' | less
}}}
reference:
http://bogdan.org.ua/2009/03/30/linux-how-to-remove-trailing-control-m-carriage-return.html

沒有留言:

張貼留言