Please help to write a executable script for extracting some parts of a file
Hi All,
I am very new in programming. I need some help.
I have one input file like:
I want to create some output like:
Out file1.txt(which grep from, next line of "Taxonomy:" upto "+++++++++++End" ) with no space in front of line and so on.
So the desired ouput will be: (with no space in front of the names)
outfile1.txt
Gammaproteobacteria: 2767
Alphaproteobacteria: 4123
Deltaproteobacteria: 1343
Epsilonproteobacteria: 26
Betaproteobacteria: 397
unclassified Proteobacteria: 48
Spirochaetes (class): 15
Nitrospira (class): 1
Bacilli: 25
Not assigned: 1445
No hits: 220253
outfile2.txt
Gammaproteobacteria: 2809
Alphaproteobacteria: 4001
Deltaproteobacteria: 1208
Epsilonproteobacteria: 15
Not assigned: 299
No hits: 461890
and so on.
I got several helps from this forum. Thanks to durden_tyler, ghostdog74 and summer_cherry .
But still there is little problem so I am posting again.
Can anybody please help me in this matter?
The perl code below works (without the marked line in the code) but provides out file with spaces in front of line. I tried to get rid of the space but couldn't.
One more code by durden_tyler works perfectly (but only in terminal, I failed to create a executable file with this)
----------------------------------------------------------
I tryed in this way(below). But couldn't make it.
-------------------------------------------------------------------
From the help with Python also I couldn't make it properly
% code.py
Usage: code.py <input file>
%
---------------------------------------------------------
Please help in this matter. I want to prepare one executable script (perl/python/pr bash)..
Many thanks in advance...
Please help.
Best wishes,
Mitra
first, where did you define "input file"?? input file should be defined
eg
for line in open("input file") <------ means you want to open the file with name of "input file"
also the output of the script has spaces removed.
so i don't see why it don't work for you.
Hallo,
Thanks for your reply.
I am very new in programming. Probably that is why I couldn't make it.
My try was :
and tried to execute by:
./code.py filename
Please help. I am really trying to learn.
Thanks a lot,
Mitra.
you are mixing shell syntax with Python.
on command line, just give : python myscript.py inputfile
if you want to use the script, at least read up on Python and how to use it. same with Perl if you want to use the Perl script, read the documentation.
Hallo ghostdog74,
Thank you very much for your help. I am trying to learn with the tutorials and documentation. But being new I am always mixing these. Sorry for that.
Thank you very much once again.
Best,
Mitra
Hallo ghostdog74,
I am sorry if I am again making any mistake. I used the code as you said. but still there is some problem in o.close()
The error is :
If I make one false line(o=) as below
Then it works perfectly (only creating one extra blank file out_0.txt)
But can you please tell me whats the problem. Sorry if I am disturbing you so much. But I am really trying to learn.
Best regards,
Mitra.
Dear Experts,
I am an ERP consultant and would like to learn shell script. We are working on Linux SUSE 11.4 and I am very new to shell scripting. We can manually encrypt an excel file using "executable jar" through command prompt by placing the jar file & the file to be encrypted on a physical... (1 Reply)
I have number in file which contains date and serial number:
2013101000.
The last two digits are serial number (00). So maximum of serial number is 100.
After reaching 100 it becomes 00 with incrementing 10 which is day with max 31.
after reaching 31 it becomes 00 and increments 10... (31 Replies)
I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file.
Kindly provide your input.
File is like below
Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Hi,
How can I extract parts from an absolute path?
For example :
The absolute path is /dir1/dir2/dir3/dir4/dir5.I need the relative path starting with directory given as parameter : for instance if the parameter is dir3 then the result should be dir3/dir4/dir5
I need generic solution... (9 Replies)
Hi,
I want to write an executable file in unix env to go to a particular path instead of always typing the long path cd /app/oracle/product/10.2.0/Db_1/scripts/prejib/sample.
I have tried with the below script in but not working . please help me
bash-3.00$ cat a.sh
#!/bin/sh ... (3 Replies)
Dear list
its my first post and i would like to greet everyone
What i would like to do is select records 7 and 11 from each files in a folder then run an executable inside the script for the selected parameters.
The file format is something like this
7 100 200
7 100 250
7 100 300 ... (1 Reply)
Hello,
I have a XML file as below and i would like to extract all the lines between <JOB & </JOB> for every such occurance. The number of lines between them is not fixed.
Anyways to do this awk?
============
<JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1"... (3 Replies)
hi
i have file extentioned with test.vbs. i am able to run this file n execute through command promt but i dont know how to run in shell script
example:
file name is test.vbs which contains
strSoundFile = "C:\windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand... (5 Replies)
hi i'm trying to use tcl/tk on unix machine to call an executable C file ..
i am trying just a simple button like this one
button .list -text "LIST" -command filename
pack .list -padx 10 -pady 10
but its giving me error message when i save it in a file eg script.tcl
the button is... (7 Replies)
I need an assistance in file generation using awk, sed or anything...
I have a big file that i need to filter desired parts only. The objective is to select (and print) the report # having the string "apple" on 2 consecutive lines in every report. Please note that the "apple" line has a HEX... (1 Reply)