Monday, May 7, 2012

recursively remove broken symlinks in bash

Weblog for atrixnet - recursively remove broken symlinks in bash

Posted by Anonymous (78.32.xx.xx) on Sat 27 Sep 2008 at 01:00
Totally cheating, but after searching for "exist" in the GNU find man page:

find -L . -type l -print0 | xargs -0 --no-run-if-empty rm

With -L (follow symbolic links), -type l matches against the type of the link's target (recursively following links if it's a symlink to a symlink) - unless that target does not exist, in which case it matches against the link.

(The -print0 and -0 options are specific to GNU find and xargs, and allow you to operate on files with bizarre names, e.g. containing newlines, by using the \0 (NUL) character as the line separator. There are only two characters not allowed in Unix filenames - NUL and '/'.)

If that's too subtle, here's a more long-winded solution:

find . | while read -r FILE; do
if ! test -e "$FILE"; then
rm "$FILE"
fi
done

Linux or Unix find and remove files with one find command on fly

Linux or UNIX - Find and remove file syntax

To remove multiple files such as *.jpg or *.sh with one command find, use

find . -name "FILE-TO-FIND"-exec rm -rf {} \;

OR

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

Thursday, May 3, 2012

How can i edit some rows in .bam header file? - BioStar

How can i edit some rows in .bam header file? - BioStar


Question: How can i edit some rows in .bam header file?

 
2
 
 

For example i have the following already in the bam header:

@RG ID:110131_SN107_0398_A81DDCABXX_LANE2   PL:ILLUMINA LB:P0007    SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE4 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE6 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE8 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE2 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE4 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE6 PL:ILLUMINA LB:P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE8 PL:ILLUMINA LB:P0007 SM:tumor

i want to make it:

@RG ID:110131_SN107_0398_A81DDCABXX_LANE2   PL:ILLUMINA LB:tumor_P0007  SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE4 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE6 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0398_A81DDCABXX_LANE8 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE2 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE4 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE6 PL:ILLUMINA LB:tumor_P0007 SM:tumor
@RG ID:110131_SN107_0399_B81CYUABXX_LANE8 PL:ILLUMINA LB:tumor_P0007 SM:tumor

Thanks.

 
 

1 answer



 
12
 
 
 

samtools view -H mybamfile.bam | sed -e 's/LB:/LB:tumor_/' | samtools reheader - mybamfile.bam > mybamfile.reheadered.bam

Wednesday, February 8, 2012

scp as a background process

scp as a background process « Kunal Bharati
scp as a background process

To execute any linux command in background we use nohup as follows:

1 $ nohup SOME_COMMAND &

But the problem with scp command is that it prompts for the password (if password authentication is used). So to make scp execute as a background process do this:

1 $ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1

Then press ctrl + z which will temporarily suspend the command, then enter the command:

1 $ bg

This will start executing the command in backgroud
Advertisement
Share this:

Share

Like this:
Like
Be the first to like this post.

Tags: Linux, tips n tricks