[Show all top banners]

Junkiri
Replies to this thread:

More by Junkiri
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Help writing a shell script
[VIEWED 4562 TIMES]
SAVE! for ease of future access.
Posted on 06-29-07 12:46 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi All,

I need some help writing a script in bash shell that does the following.
I have a bunch of files with letters before some numbers ( those numbers are the identifiers of the files that I will finally need to weed out). I need to remove the letters before the numbers so that the file name start with the numbers alone (I don't care about the letters after the numbers). Here's an example of what I have and what I want finally to make things more clear:

What I have now: SGDUNK223.R_D02_08.ab1
What I'd like to have: 223.R_D02_08.ab1

I could either do this one by one....but figured a script could make my llife a lot easier and I could do more interesting stuff like visiting sajha :D.
 
Posted on 06-29-07 1:12 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I dont know in Shell but in SAS you can use the SUBSTR function. I guess there has to be something similar in shell s. Prob this is what u want.
http://www.linuxforums.org/forum/linux-programming-scripting/44758-extracting-substring-string.html
 
Posted on 06-29-07 1:23 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

There should be an easier way to this...Thanks anyway....any Unix experts out there?
 
Posted on 06-29-07 1:33 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

U can write a macro in sas that would do all that in one step. Sorry
There are some experts here. Well I failed my last interview just bec of that question
 
Posted on 06-29-07 3:13 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hope this one helps. If you are looking for something else, let me know..

#!/bin/bash

MYVAR="SGDUNK223.R_D02_08.ab1"
NAMEONLY=`expr match $MYVAR '\([a-zA-Z]*\)'`
RESULT=${MYVAR#$NAMEONLY}
echo $RESULT
 
Posted on 06-29-07 5:11 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

yes i think |<1$|-| is absolutely correct.
that will definately work.
if not please post
i will try to help you.
but that will work
 
Posted on 06-29-07 6:23 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

what type of files are these.
Script by |<1$|-|
should work.
 
Posted on 06-29-07 9:28 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hey Unix people
How do I know how many lines of codes are there in a particular program?
 
Posted on 06-29-07 9:45 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

If you are talking about a source file, then type the following at the shell:
wc -l filename
 
Posted on 06-29-07 9:47 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi all,

Thanks so much for your help....I ended up working on other stuff and saving this for next week..So I will try the script that you suggested and hopefully this will work.Otherwise I will have to change the names individually...and doing that for 1000+ files is definitely a pain in the rear :S.
Btw, I will need to write more scripts in the future..I will probably have to look into perl or other scripting languages later on but for now I just need to polish up my shell scripting. I am actually looking for a good book for this. Any suggestions? I heard O'Reilly books are really good.

Incognito_kanchi,
Those files are actually generated from a program called sequencher, used in DNA sequencing. Thats as far as I know coz I am also relatively new to this area.

Danger,
I think this should work:

cat n1 | wc

where n1 is the name of the program (file). This gives the number of characters, words and lines in the file. Hope this helps.
 
Posted on 06-29-07 11:17 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks
I can score my next interview now.
Rookie here. Oops w/ 5 yrs of linux experince cause my sitty SAS runs on Linux and Mainframe.

By the way do you know how to transfer files from Linux to PC and Mainframe? That is another question thats bothering me???

 
Posted on 06-29-07 11:35 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

junkiri,
I use the Advanced Bash-Scripting guide
http://tldp.org/LDP/abs/html/

Danger,
There are a lot of ways to transfer files. Try rsh or ssh. You can get free ssh client for windows.
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration
TPS Re-registration case still pending ..
Democrats are so sure Trump will win
Basnet or Basnyat ??
nrn citizenship
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
ChatSansar.com Naya Nepal Chat
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
if you are in USA illegally and ask for asylum it is legal
Travelling to Nepal - TPS AP- PASSPORT
emergency donation needed
Top 10 Anti-vaxxers Who Got Owned by COVID
आज बाट तिहारको सेल सकियो
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters