Probably some stupid mistake...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Probably some stupid mistake...
# 1  
Old 01-28-2011
[solved]Probably some stupid mistake...

Hi everyone !

I have a file wich look like this :

>Sis01
[lots of ATCG stuff]

> Sis02
[lots of ATCG stuff]

...

>Sis44
[lots of ATCG stuff]


I want to separe each paragraphe in a different file, so I decide to use the "FOR" loop + sed.

Code:
for f in {01..44}
do
(
   sed -n '/^>Sis `echo $f'/,/^>/p' Sis_110125.fasta | sed '$d' > Sis_110125_contig`echo $f`
)
done

I get empty files, i think due to the space between ^> and the echoed $f


I try a lot of thing, but I was unable to find a solution !

Thanks for your help !

Last edited by sluvah; 01-28-2011 at 02:10 PM.. Reason: Solved
# 2  
Old 01-28-2011
Code:
awk '/Sis/{close(f);f=sprintf("Sis%02d",++c)}{print > f}' file

# 3  
Old 01-28-2011
You are a god !

Thank you so mutch !

Could you just help me to understand the line ? I prefer to understand what I use, at least it help me to improve my bash !

What I understand :
Code:
awk  ==> Awk program, the one to use with a table

'/Sis/{ ==> ??? Pattern to search in my file ?

close(f); ==> Empty F variable ?

f=sprintf("Sis%02d",++c)} ==> what my f variable is : Sis + number in two digit, increasing each time by one

{print > f}' ==> Print my paragraphe ? How did this paragraphe get selected by awk ???

file ==> Obviously, my file name

Thanks !
# 4  
Old 01-28-2011
Quote:
Originally Posted by sluvah
Could you just help me to understand the line ? I prefer to understand what I use, at least it help me to improve my bash !
Sure.
Code:
awk '/Sis/{close(f);f=sprintf("Sis%02d",++c)}{print > f}' file

Explanation:

/Sis/ search for the pattern and if it matches:
{close(f) close the opened file (if there was one opened) and...
f=sprintf("Sis%02d",++c)} fill the variable f with "Sis" and an increased number in 2 digits
{print > f} open a file (if it wasn't) and print the line to the file f

Hope this helps.
# 5  
Old 01-28-2011
Great !

Thanks !
# 6  
Old 01-29-2011
Code:
awk -F \> '/Sis/ {f=$2}{print > f}' Sis_110125.fasta

 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange type mistake?!

Hi, I want to start MY_PROGRAM in a bash script with additional parameters given in the CONFIGURATION_ARRAY. IFS="'" CONFIGURATION_ARRAY=( '-N 0 -m 0' '-N 0 -m 1' ) for configuration in ${CONFIGURATION_ARRAY} do //DEBUG N=${configuration%-*} //-N 0 M=-${configuration##*-} //-m 0... (5 Replies)
Discussion started by: xraystorm
5 Replies

2. UNIX for Dummies Questions & Answers

Can anyone help me to spot my mistake?

Hi there can anyone help me to spot my mistake and please explain why it appears My code : #!/usr/bin/gawk -f BEGIN { bytes =0} { temp=$(grep "datafeed\.php" | cut -d" " -f8) bytes += temp} END { printf "Number of bytes: %d\n", bytes } when I am running ./q411 an411 an411: ... (6 Replies)
Discussion started by: FUTURE_EINSTEIN
6 Replies

3. Shell Programming and Scripting

Can anyone find the mistake in this script file

#!/bin/ksh db_user=`echo $DB_USER_NAME` db_pwd=`echo $DB_PASSWORD` db_sid=`echo $TWO_TASK` sqlplus -s $db_user/$db_pwd@$db_sid << EOF a = select ACK_PARTY_NAME,bus_event_seq_nbr from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and bus_event_seq_nbr='3969094' set -- echo $a |... (17 Replies)
Discussion started by: rkrish
17 Replies

4. Red Hat

Changing Desktop Environment by mistake

Hi, I'm using fedora 15, my defualt DE is XFCE I once saw that there is a option in startup DE's that I can select and it was OPENBOX. I just wanted to test it. but after choosing it as my DE here I am. I have just access to terminal, firefox.. what's in my desktop. there is no panel here. I... (0 Replies)
Discussion started by: hoseinit
0 Replies

5. Solaris

Renamed lib directory by mistake

Let's say someone accidentally renamed the lib directory in Solaris 8, and now they cannot get into the terminal or even rename the folder via file manager.What would one do? (37 Replies)
Discussion started by: jetjaguar
37 Replies

6. Shell Programming and Scripting

Is there any mistake in this code:

cat $1 | sort -n | uniq | $1 in other words, I sort the content of the file and put the ouput in the same file, is there any mistakes in this cshell code ??? (4 Replies)
Discussion started by: Takeeshe
4 Replies

7. AIX

Did a Mistake with HACMP

Hi, I needed space on a FS, and when I've added the space on the filesystem, I did it trough the regular smitty fs inteface and not with smitty cl_lvm. Can someone help me to repair the situat before a faileover happen ? Thanks for your help,:mad: (13 Replies)
Discussion started by: azzed27
13 Replies

8. UNIX for Dummies Questions & Answers

Crontab Mistake!!!

Hi. I hope someone can help me with this problem. Being a novice to Unix, I editted my crontab directly by typing " crontab -e ". Well, I needed to make some changes so, I typed " crontab -r ". Now I have no crontab, and I can't seem to get crontab to write a new file. I' ve tried: vi... (4 Replies)
Discussion started by: cstovall
4 Replies
Login or Register to Ask a Question