LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-09-2005, 07:00 AM   #1
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: SuSE 12
Posts: 3,505

Rep: Reputation: 56
little script help needed


Hi!

I have a problem (surprise ).

I have no programming skills at all, but I need to write a script that reads data from a file (tab delimited list, three entries each line), places those three paramters in a textfile, which is then fed into a program. The goal is to run each line of parameters through this program and create a resultfile for each.

My problem is with the parsing of the inputfile. I know that I may be able to solve my problem by reading sed/awk/perl/bash manuals, but I do this for several hours already without making major advances.

So if you are a programming specialist, for whom this is a task of several seconds, could you please push me into the right direction (maybe with an example script)? Thank you very much!

More info:

Input file:
Code:
1	CTTGCTATTGGTAAGGAAACTG	GTATTTGTGCTCTGGGAAGAC
2	CTTGCTATTGGTAAGGAAACTG	TATTTGTGCTCTGGGAAGAC
3	CTTGCTATTGGTAAGGAAACTG	ATTTGTGCTCTGGGAAGAC
4	TTGCTATTGGTAAGGAAACTGG	GTATTTGTGCTCTGGGAAGAC
...
Temporary text file:
Code:
PRIMER_SEQUENCE_ID=NUM
PRIMER_LEFT_INPUT=FWD
PRIMER_RIGHT_INPUT=REV
PRIMER_PICK_ANYWAY=1
PRIMER_MIN_TM=55
PRIMER_EXPLAIN_FLAG=1
...
The parameters to be replaced are NUM, FWD and REV (can be renamed).
 
Old 07-09-2005, 07:35 AM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
I would use cut for parsing the file, and no need of sed, awk nor perl
Code:
#!/bin/bash

datafile="/path/to/datafile"
prefix="config_"
savedir="/path/to/dir/where/save/configs"

while read line; do
    SEQUENCE_ID=$(echo $line | cut -d' ' -f1)
    LEFT_INPUT=$(echo $line | cut -d' ' -f2)
    RIGHT_INPUT=$(echo $line | cut -d' ' -f3)
    cat <<END > "$savedir/$prefix$SEQUENCE_ID"
PRIMER_SEQUENCE_ID=$SEQUENCE_ID
PRIMER_LEFT_INPUT=$LEFT_INPUT
PRIMER_RIGHT_INPUT=$RIGHT_INPUT
END
done < $datafile

for file in $(find $savedir -name "$prefix*"); do
cat <<END >> $file
PRIMER_PICK_ANYWAY=1
PRIMER_MIN_TM=55
PRIMER_EXPLAIN_FLAG=1
...
END
done
Of course I assume PRIMER_SEQUENCE_ID is uniq, I mean
the number corresponding to the first field in your datafile
 
Old 07-09-2005, 08:07 AM   #3
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: SuSE 12
Posts: 3,505

Original Poster
Rep: Reputation: 56
Thank you very much!

It took a while, but I think I understand what this is doing.

Is it correct that this script creates a config file for each entry in my datafile? First it writes out the variable information and in the second step, it adds the fixed part to the files (cat). Correct? Great! I think this is all I needed. Thanks again!
 
Old 07-09-2005, 08:35 AM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
Yes, I opted for Keep It Simple way
 
Old 07-09-2005, 04:53 PM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 32
sed is neater:
Code:
sed 's/\([^^I]*\)^I\([^^I]*\)^I\([^^I]*\)/PRIMER_SEQUENCE_ID=\1
PRIMER_LEFT_INPUT=\2
PRIMER_RIGHT_INPUT=\3
PRIMER_PICK_ANYWAY=1
PRIMER_MIN_TM=55
PRIMER_EXPLAIN_FLAG=1/'   inputfile
(The ^I represents a tab character.)

A single command will run much quicker than the cumbersome script, too.

[edit] Sorry, I've just reread your post and seen you want each line in a separate file.

Last edited by eddiebaby1023; 07-09-2005 at 04:56 PM.
 
Old 07-09-2005, 05:35 PM   #6
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: SuSE 12
Posts: 3,505

Original Poster
Rep: Reputation: 56
Thanks anyway, maybe I'll learn something. sed always scares me a bit, because of the special characters and regular expressions. Very confusing!

After I got keefaz's script, everything was easy. I rewrote the code a little (now I can use a more complicated inputfile) and could check several thousand lines in a few minutes. Nice!
 
Old 07-11-2005, 08:06 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
That looks like DNA sequences.
Are you creating a monster?

 
Old 07-11-2005, 08:37 AM   #8
abisko00
Senior Member
 
Registered: Mar 2004
Location: Munich
Distribution: SuSE 12
Posts: 3,505

Original Poster
Rep: Reputation: 56
Quote:
Originally posted by bigearsbilly
That looks like DNA sequences.
Are you creating a monster?

You are right! My monsters are green and totally useless (in an economical sense): I am a plant researcher, working with Arabidopsis thaliana (http://www.arabidopsis.org/info/aboutarabidopsis.jsp ).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script help needed Henster Linux - General 4 08-21-2005 09:54 AM
Help Needed with Firewall Script extremebfn Linux - Networking 0 09-04-2004 03:56 PM
(Perl?)Script needed Cyrus XIII Programming 5 01-03-2004 11:45 AM
Backup script needed jmirles Programming 1 09-27-2003 08:50 AM
Bourne Script Help Needed JCScoobyRS Linux - General 4 03-03-2003 04:46 PM


All times are GMT -5. The time now is 08:53 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration