UNIX newbie with a really odd result!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX newbie with a really odd result!
# 1  
Old 01-21-2010
UNIX newbie with a really odd result!

I am relatively new to UNIX and am having some really weird results with redirecting output. I will start at the beginning.

I have a file with consists of a list of a chemical name followed by a tab and then a string of characters known as a SMILE string in this format

Code:
PS_1    C=C
PS_2    C-C-N
PS_3    C-C=C

the list is 22 lines long.

I am using csplit to split the file (the file is called 22hits) into multple individual files using this command:

Code:
csplit -skf seq 22hits '/PS_/' {20}

BTW, I am confused about why I have to use the number 20 instead of 22 if I want 22 separate files. Regardless, that is something I figured out by trial and error. This is not the major problem, however.

The resulting files have the name seq00, seq01, seq 02 etc. and contain and individual line of data including the name of the chemical and the SMILE string.

Now, to rename the files to the chemical names, I am using the following shell script:

Code:
#!/bin/sh
#Rename split chemical files
file="$1"
    fastaname=`cat $1 | perl -pi -e 's/\t/\n/g' | grep 'PS_'`
    echo $fastaname
    mv $1 $fastaname

This script changes the tab between the name of the chemical and the SMILE string to a newline, retrieves the name alone and then renames the file with that name.

Additionally, I am trying to remove the name of the compound in the file so that I have a file named PS_1 for example, and the only information it contains is the SMILE string, not the name of the compound, followed by a tab, followed by the SMILE string.

To accomplish this, I am using the following script:

Code:
#!/bin/sh
cat $1 | perl -pi -e 's/\t/\n/g' | grep -v 'PS_' > $1

Again, I am replacing the tabs with newlines, returning the line that does not have 'PS_', which should be the smile string, and then directing that output to the file. The problem is....for some files, i get the desired results, and for others, the file comes back with all data removed. The bigger problem is, I can repeatedly run this series of scripts on the same file (22hits) and get different results every time. Sometimes, half have the desired result, and the other half have the data deleted. Other times, only a few have the data deleted and the others have the desired result.

This is really confusing!!! Can anyone help??

Last edited by pludi; 01-22-2010 at 02:30 AM.. Reason: code tags, please...
# 2  
Old 01-21-2010
wait a second.....
If i understand it correctly

u have n number of lines like

PS_1 C=C
PS_2 C-C-N
PS_3 C-C=C

and u want to create files like PS_1 which has C=C
and PS_2 which has C-C-N and so on

If thats the case

Code:
cat infile  | perl -e 'while(<>){ chomp ; my ($file_name,$content) = split("\t"); `echo $content > $file_name`;}'

Where infile contains
Code:
cat infile
PS_1    C=C
PS_2    C-C-N
PS_3    C-C=C


If you want to do it using awk

Code:
awk '{print $2 > $1} infile

HTH,
PL

Last edited by daptal; 01-21-2010 at 09:43 PM..
# 3  
Old 01-21-2010
Re:

Wow thanks for the fast response. Yes you understood the overall problem correctly, and your solutions seem much simpler even though I don't completely understand all of the commands. I tested the script and it does exactly what you said it would on the test file containing PS_1, PS_2, etc. Unfortunately, the SMILE strings are a little more complicated and include a few characters that seem problematic. This is an example:

PS_1 CCOC(=O)C1C(CC2=C(C(C3=C(C)C=CS3)C(=C(C)N2)C(=O)OCC)C1=O)C4=CC=CC=C4OC

I'll try to modify the script so that these characters (I think its the parentheses) are not problematic. Hopefully I can figure this out. Do you know an easy solution?

Thanks again!
# 4  
Old 01-21-2010
The Problem was
Code:
`echo CCOC(=O)C1C(CC2=C(C(C3=C(C)C=CS3)C(=C(C)N2)C(=O)OCC)C1=O)C4=CC=CC=C4OC > PS_1'

Replace
Code:
echo $content > $file_name

echo "$content" >  $file_name

HTH,
PL
# 5  
Old 01-21-2010
Re:

Thanks Daptal! That did exactly what I wanted. Time to figure out what exactly is going with all of the commands.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX for newbie

i very newbie unix i already download FreeBSD-10.0-RELEASE-i386-disc1 but i don't know how to use it can anyone tell me, i use win 7 and i like to learn, i read a book teach your self unix in 24 hour but not told me how i do the first time do i need to made dual boot ? in windows system what... (4 Replies)
Discussion started by: hle
4 Replies

2. UNIX for Dummies Questions & Answers

Help for Unix Newbie

Hi all, 1. How are we going to call .cmd files which is in window under Unix Environment? 2. Is there any equivalent command in Unix for "start" which is available in Windosw? Thx very much. (5 Replies)
Discussion started by: jessy83
5 Replies

3. UNIX Desktop Questions & Answers

unix newbie

Hi everyone! Thanks for taking the time. I've installed redhat and ubunto on vmware virtually. I want to try unix and I tried to look in the internet but wasn't able to accomplish my desire task. Any links for install, download links and information will be honestly appreciated. I will be... (6 Replies)
Discussion started by: michaelttkk
6 Replies

4. UNIX for Dummies Questions & Answers

Odd result from cp -R foo/.* bar

I'm not all that much of a newbie but I've not encountered this before. Happens both in Cygwin and in Mac OS X (Darwin): cp -R /path/to/foo/.* /path/to/bar (where directory 'bar' exists) ... seems to copy not only the contents of directory 'foo', but also other directories that are... (3 Replies)
Discussion started by: ChapHarrison
3 Replies

5. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

6. UNIX for Dummies Questions & Answers

I'm a newbie to unix

i have just installed UNIX 7.01 to replace a windows server2003 used for my family to share and remotely save photos i need to set it up so very novice users can view, import and export photos most of the remote users will have windows machines,i use Linux, Mac and windows. most of what i want... (2 Replies)
Discussion started by: chance63
2 Replies

7. Shell Programming and Scripting

Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix

Hi Can we call a jsp page from Unix.if so please let me know how we can.. thanks for the help in advance... thanks kumar (0 Replies)
Discussion started by: mailsukumar
0 Replies

8. Shell Programming and Scripting

Newbie to HP Unix

Hi Im a newbie to unix having been a windows guy, yes I know a swear word on here ? but part of my new job is to be trained up on Unix. On the course we were set a task to read a file that has dates times codes etc, a log file. see below as an example 2007/02/19 00:00:06: Information: Switch... (3 Replies)
Discussion started by: MyNameisEarl
3 Replies

9. UNIX for Dummies Questions & Answers

hello unix newbie

hi im new to unix i use windows on my home pc the reason i registered is because im finishing up a UNIX class this year. all i have left is the exam but i had a lot of personal problems and didnt do a lot of work; the teacher is letting me make it up but its hard for me to learn a whole unix... (1 Reply)
Discussion started by: Combat Form
1 Replies

10. UNIX for Dummies Questions & Answers

Newbie to Unix

Hey, I've been a windows guy all my life, but i have finally decided to move to Unix and buy a Mac. I am pretty good with a lot of programming applications on windows, but was wondering if u guys had any advice on how to get started on Unix, like books to read, applications to buy, websites,... (8 Replies)
Discussion started by: Mafia
8 Replies
Login or Register to Ask a Question