Regexpr expertise required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regexpr expertise required
# 1  
Old 10-27-2009
Regexpr expertise required

Any experts on regular expressions out there, can you help me rationalise this?

In this post: -

https://www.unix.com/shell-programmin...-points-2.html

I use the code: -

Code:
tmp = $1 ; gsub(/00/, ".") ; $1 = tmp
        tmp = $1 ; gsub(/A[CGT]|C[GT]|GT/, "0") ; $1 = tmp
        tmp = $1 ; gsub(/AA/, "-1") ; $1 = tmp
        tmp = $1 ; gsub(/TT/, "1") ; $1 = tmp

This is because the gsub's work on the entire record but I want to exclude $1. Can anyone tell me the elegant way to do this just using the regular expression to exclude $1?

Thanks

Last edited by steadyonabix; 10-27-2009 at 02:54 PM..
# 2  
Old 10-27-2009
You can't do all the substitutions with one regular expression but it's redundant to assign the value to tmp and vice versa 4 times. This should be sufficient:

Code:
tmp = $1
gsub(/00/, ".")
gsub(/A[CGT]|C[GT]|GT/, "0")
gsub(/AA/, "-1")
gsub(/TT/, "1")
$1 = tmp

# 3  
Old 10-27-2009
Cheers Franklin. I do have a tendency to cut and paste inefficient solutions as a quick fix while intending to come back with a proper solution.

However what I really want to do is exclude $1 within the regular expression itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Expertise advice required <<URGENT>>

:eek:i hav a shell script in my linux server, i want to execute it everyday once automatically without using cron tabs as i dont hav permission to create one. So wht sld i do??:confused: (1 Reply)
Discussion started by: Jay Thakkar
1 Replies

2. Shell Programming and Scripting

Need expertise on awk

Hi everyone. I need some help on how to fix this. I am getting positive result using the log file below and this command awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$2 ~ t && $7 ~ main { first = $0; getline; } first && $7 ~ trig { printf "%s\n", first; exit }' log ... (5 Replies)
Discussion started by: cwiggler
5 Replies

3. Shell Programming and Scripting

Help required

Dear All, I need to script to change TTL of all zone file in my DNS and aslo i require the serial to be updated to reduce my work load. Regards Vicky (0 Replies)
Discussion started by: search4u2003
0 Replies

4. UNIX for Dummies Questions & Answers

With expertise in the shell I want to help necessary to resolve project and wish you

Hello to all of you my friends That your friend's new in this forum and Otnmy you to help me to solve this small-scale project I would be grateful to you too The URL for the file that explains that the project (1 Reply)
Discussion started by: دجحخهعدج
1 Replies

5. Shell Programming and Scripting

With expertise in the shell I want to help necessary to resolve project and wish you a happy life

Hello to all of you my friends That your friend's new in this forum and Otnmy you to help me to solve this small-scale project I would be grateful to you too The URL for the file that explains that the project os-lab-Search_projectFall2009.pdf (1 Reply)
Discussion started by: دجحخهعدج
1 Replies

6. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

7. Solaris

x11vnc & tightvnc Expertise Required !

Hi all, For the past 3 days I have been struggling like :mad: to setup a VNC system between a solaris 8 unix host server and a windows XP tightvnc client viewer. Please bear in mind that the unix machine is crap & probably should be taken to the "Antiques Road Show on the BBC". Everything is... (2 Replies)
Discussion started by: fawqati
2 Replies

8. Shell Programming and Scripting

Problem with sed and negative regexpr's

I have a file with various syntax that I'm try to run sed on to change over a specific regexp and having problems. I want to swap all instances of a token so long as the token isn't followed by either an alphanumeric character, an underscore, or an exclamation point. The test file looks like... (1 Reply)
Discussion started by: ericbmn1
1 Replies

9. Linux

Help Required

Hi, please suggest me the possible reasons for application to get hang ???? Thanks and Regards Anand P (1 Reply)
Discussion started by: Anand Prakash
1 Replies

10. Solaris

Help required.

Hi, Iam relatively new to Shell scripting. ............ ......... Cur_log_file=`ls -lrt LOGFILE* | grep 'Jun 30' | tail -1` ............... .................. Iam trying to find some log file name to check their status, using above script line. If the log file is not avaible then rest of... (3 Replies)
Discussion started by: Lokesha
3 Replies
Login or Register to Ask a Question