AWK Help needed - Production Issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Help needed - Production Issue
# 1  
Old 10-05-2009
AWK Help needed - Production Issue

Hi

I have a cross reference file which contains 86000 records. The data is old number:new number. There are 100s of files where i need to search for old number and append corresponding new number (preceded by @) to the line containing old number. The files contain millions of records.
Currently I am using sed command as below:

Code:
  sed "/$v_s_replace_string/s/$/$v_s_new_string/" $v_s_file_name > tempfile1
  mv tempfile1 $v_s_file_name

v_s_replace_string = contains old number
and v_s_new_string = contains new number

I need to replace this sed command with and awk command as awk is faster than sed.

Please help.
Thanks

Last edited by Franklin52; 10-05-2009 at 03:35 AM.. Reason: Please use code tags!
# 2  
Old 10-05-2009
its similar.. I don't think it will make any huge diff..
Code:
awk -v old=$v_s_new_string  -v old=$v_s_replace_string  '{gsub(old,new)}1' $v_s_file_name > tempfile1
mv tempfile1 $v_s_file_name

# 3  
Old 10-05-2009
Hi
Thanks for your solution.

I am trying that.
Is there any other option that you can suggest. I need to speed up the processing as much as possible. It is a production run and my script should not take more than 5 mins per file.

Thanks
# 4  
Old 10-05-2009
Did you try command line perl or a perl script .
# 5  
Old 10-05-2009
Hi

For the awk command... could you please modify it to append the new number at the end of the line where it finds a match with old number. The command you gave is adding the new number to begining of the line. I am new to awk. Please help.
# 6  
Old 10-05-2009
you mean this??
Code:
awk -v var=$v_s_replace_string  '{if($0 ~ '/$v_s_new_string'/}{print $0":"var}else{print}}' $v_s_file_name > tempfile1
mv tempfile1 $v_s_file_name

# 7  
Old 10-05-2009
Hi
Thanks for your help and time. But the code you sent is not helping.
It is appending all the new number strings to one record only.

I need to appedn the new number only to that record where it matches the corresponding old number.

I tried this:
Code:
awk -v var=$v_s_new_string  /$v_s_replace_string'/{print $0""var}' $v_s_file_name > tempfile1
mv tempfile1 $v_s_file_name

Please help.

Last edited by Franklin52; 10-05-2009 at 03:35 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue with ACL's (Help/Advice Needed)

Hi Experts,,, Need your help/advice on how to fix this I have 2 users under same group (primary group) and i want to give 777 permissions on a directory to one dir owned by user1 when granted i can see than from getfacl but when i actually login as user2 i can touch a file . ... (3 Replies)
Discussion started by: maddyfreaks1
3 Replies

2. AIX

Production Issue in AIX Oracle RAC [errpt output : DUPLICATE IP ADDRESS DETECTED IN THE NET]

1)We have 2 node cluster RAC on AIX: ->test1 ->test3 2) After rebooting server both the node sequentailly, we are getting below error from errpt command : # errpt |more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION FE2DEE00 0901223914 P S SYSXAIXIF DUPLICATE IP ADDRESS... (2 Replies)
Discussion started by: manjusharma128
2 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. Emergency UNIX and Linux Support

AIX: Production email issue

Hello, system generated emails sent to users from production scripts within Aix arent going out. In the errpt -a output I see: _______________________________________________________ LABEL: SRC_SVKO IDENTIFIER: BC3BE5A3 Date/Time: Tue Mar 13 16:28:07 EDT 2012 Sequence... (2 Replies)
Discussion started by: NycUnxer
2 Replies

5. Shell Programming and Scripting

awk help needed

Hi, i have input records as shown below. 4097,Probe3,G10,255,05/17/2011 12:44:03:185,NULL,05/17/2011 12:39:03:180,05/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

6. BSD

Copying OpenBSD Kernel from a non production to production machine

Hi All, There are few OpenBSD 4.8 servers without compiler installed at my working place. However, sometimes there are some patches released for patching the kernel. My question is: Can I setup a non production OpenBSD 4.8 server as a test machine with compiler installed and use it to... (1 Reply)
Discussion started by: lcxpics
1 Replies

7. Red Hat

Help needed in fixing port issue - Urgent

Hi, One of our web application is running in Linux and using apache web servers. Application is hosted in port 4080 (for soap requests) and port 9999, and its serving behind a vip and cname. Initially it was working fine in another server and recently (2 months back) we have moved to the new... (4 Replies)
Discussion started by: senor.ram
4 Replies

8. Shell Programming and Scripting

production issue - shell sqlplus processing sometime success sometime fail

Hi Expert, Below is a real production environment issue: we are using shell script to FTP to a remote server and fetch around 150 files every day, for each file we need to keep a entry inside ORACLE DB table, before insert into table, each file has a associated logid, which need to be... (2 Replies)
Discussion started by: summer_cherry
2 Replies

9. Shell Programming and Scripting

urgent help needed in telnet issue

Hi, Whenever i am trying to telnet to server i am getting frequent error Authorized Login: prtsrc's Password: /dev/pts/171: Password read timed out -- possible noise on port when i am rerunning the same it is working fine thanks, sam (2 Replies)
Discussion started by: sam99
2 Replies

10. Shell Programming and Scripting

awk help needed

How do I alter this command so that it prints only the second comma delimited field from line number 3? Secondly, how do you redirect the output to a variable called TEST? Thanks (cat BATCH007.TXT | awk 'BEGIN { FS = "," } ; {print $2 }') (5 Replies)
Discussion started by: ddurden7
5 Replies
Login or Register to Ask a Question