Plz explain the process of this code....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Plz explain the process of this code....
# 1  
Old 01-11-2011
Plz explain the process of this code....

Hi Unix Gurus,

Please explain the processing done by the code mentioned below:

Code:
for (i=1;i<=59;i++)
	{
	    sub(/  *$/,"", $i)
	}
	newrec_key = $2
	new_line = $0
	if (empty_oldfile==1)
	{
		#newly added record
		++num_add
		print "Added key: ", newrec_key > LogFile

		#print out the newly added record
		print new_line > OutputFile

	}

Thanks
# 2  
Old 01-11-2011
Is that awk? Telling us what language you have would help us help you. Assuming awk or something close, the code in blue looks like it is taking each of the first 59 fields in the record and dropping any trailling spaces.
# 3  
Old 01-11-2011
yes...it is awk.....
# 4  
Old 01-11-2011
Code:
for (i=1;i<=59;i++)     #loop through 59 fields in each line of the input
	{
	    sub(/  *$/,"", $i)      #remove all spaces in each field
	}
	newrec_key = $2
	new_line = $0
	if (empty_oldfile==1)    #this variable might be somewhere in the code you didn't paste here
	{
		#newly added record
		++num_add
		print "Added key: ", newrec_key > LogFile   #output the 2nd field to "LogFile"

		#print out the newly added record
		print new_line > OutputFile          #copy the whole line to "OutputFile"

	}

# 5  
Old 01-12-2011
hey thanx......
its has helped me in understanding the correct logic here....
thanks a lot!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please explain what this code is doing

Hi, Pls explain me what the below code is doing. specially meaning if -a while calling test function- case $1 in 1) beg_dt=01; end_dt=07 ;; 2) beg_dt=08; end_dt=14 ;; 3) beg_dt=15; end_dt=21 ;; 4) beg_dt=22; end_dt=28 ;; 5) beg_dt=29; end_dt=31 ;; esac test \( `date +%w` -eq $2 -a... (3 Replies)
Discussion started by: sendtoshailesh
3 Replies

2. Shell Programming and Scripting

plz explain the execution flow

CODE file=/tmp/rap54ibs2sap.txt trap "rm $file; exit" 0 1 2 3 15 trap rm $file execution result trap -- 'rm /tmp/rap54ibs2sap.txt; exit' EXIT trap -- 'rm /tmp/rap54ibs2sap.txt; exit' SIGHUP trap -- 'rm /tmp/rap54ibs2sap.txt; exit' SIGINT trap -- 'rm /tmp/rap54ibs2sap.txt;... (1 Reply)
Discussion started by: rrd1986
1 Replies

3. Shell Programming and Scripting

Explain this AWK script plz

Hi frnds, one my frnds has given resolution for my problem as below. it working great , but i couldnt understand somethings in the script. Why ++ operator after the function calling. how these each block working. will each run for each input line sequencially or one block for all the lines... (9 Replies)
Discussion started by: Gopal_Engg
9 Replies

4. Shell Programming and Scripting

Can any one explain what this code will do

ccc_con,CCC_CON,0 Above is the input for this code #!/usr/bin/bash my_path=`dirname $0` T_table=$1 S_table=$2 P_table=$3 #Star new code while read ${my_path}/arch_table_list.txt { awk -F "," '{print $1}' ${my_path}/arch_table_list.txt ${S_table} awk -F "," '{print... (1 Reply)
Discussion started by: scorp_rahul23
1 Replies

5. UNIX for Advanced & Expert Users

explain the code

Hi , Can anyone explains what does the below highlighted statements means: # Set environment variables . ${0%/*}/wrkenv.sh jobName_sh=${0##*/} jobName=${jobName_sh%.*} Thanks, Sri (1 Reply)
Discussion started by: srilaxmi
1 Replies

6. Solaris

Can u explain login process in solaris

Can u explain login process in solaris detaily.. (4 Replies)
Discussion started by: Jinu
4 Replies

7. Shell Programming and Scripting

explain plz

can u explain this step by step........plz...will it do the same for I in *.tar.gz; do A=`basename $I .tar.gz` mkdir $A cp marking-guide ${A}/$A cd $A gunzip -c ../$I | tar xf - cd.. done thnx __________________ (2 Replies)
Discussion started by: avikal
2 Replies

8. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies

9. UNIX for Dummies Questions & Answers

explain command plz

echo -n "1. Updating Password Policy in OID..." | tee -a $logfile set ldap_v1 = `ldapsearch -b "" -h $oid_host -p $oid_port -D "cn=orcladmin" -w $admin_pwd -s sub "cn=PwdPolicyEntry" dn | head -1` echo "dn:$ldap_v1" > ldap1.out echo "changetype:modify" >> ldap1.out echo... (2 Replies)
Discussion started by: maoro
2 Replies

10. UNIX for Advanced & Expert Users

Can anyone explain plz

HI, Can anyone explain to me how does the following command work - > current_dir=`cd \`/usr/bin/dirname $0\` && pwd` Regards, Ranga (3 Replies)
Discussion started by: r_W213
3 Replies
Login or Register to Ask a Question