hw to insert array values sequentially in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting hw to insert array values sequentially in a file
# 1  
Old 10-20-2008
Bug hw to insert array values sequentially in a file

Hi All Smilie,
I am very new to unix. I am requiring ur help in developing shell script for below problem.
I have to replace the second field of file with values of array sequentially where first field is ValidateKeepVar

<File>
UT-ExtractField 1 | &LogEntry &Keep(DatatoValidate)
VA-ValidateKeepVar 05 &DatatoValidate
Comment Verify Recording Entity
UT-ExtractField 2 | &LogEntry &Keep(DatatoValidate)
VA-ValidateKeepVar LRP_SpsRA_MLP300 &DatatoValidate
Comment Verify Recording Entity Role (16=Requesting/Home/Serving LP)
UT-ExtractField 3 | &LogEntry &Keep(DatatoValidate)

<End of File>
Kindly help me.
# 2  
Old 10-20-2008
Hi,
below may help you, use array (100,200,300) to replace the third field if match 'ValidateKeepVar', if the lines need to be replaced more than array, the exceed lines will use the last item of that array.

Code:
nawk -F"[-| ]" 'BEGIN{
n=split("100,200,300",arr,",")
i=1
}
{
	if($2=="ValidateKeepVar")
	{
		$3=arr[i]
		print
		if(i<n)
			i++
	}
	else
		print
}' filename

output:

Code:
UT-ExtractField 1 | &LogEntry &Keep(DatatoValidate)
VA ValidateKeepVar 100 &DatatoValidate
Comment Verify Recording Entity
UT-ExtractField 2 | &LogEntry &Keep(DatatoValidate)
VA ValidateKeepVar 200 &DatatoValidate
Comment Verify Recording Entity Role (16=Requesting/Home/Serving LP)
UT-ExtractField 3 | &LogEntry &Keep(DatatoValidate)

# 3  
Old 10-21-2008
Question

ThanxSmilie Summer_cherry for ur reply, but while using that script.....M getting error message "command not found :nawk"

Wat could b the reason for that??
# 4  
Old 10-21-2008
nawk we use in solaris, try to put awk and check for the output..

Thanks
Namish
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass an array to awk to sequentially look for a list of items in a file

Hello, I need to collect some statistical results from a series of files that are being generated by other software. The files are tab delimited. There are 4 different sets of statistics in each file where there is a line indicating what the statistic set is, followed by 5 lines of values. It... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

2. Shell Programming and Scripting

Insert values into a file 0 as per the date wise

Hi The file contains 12 months of date and less than 12 months of data I want to display if date filed less than 12 months of data I want to insert a value amount 1 to amount4 0 and dates as well. 12345|Date|cntry|amount1|amount2|amount3|amoun4... (2 Replies)
Discussion started by: jagu
2 Replies

3. UNIX for Dummies Questions & Answers

Passing values from file into array in Bash

Hi, I'm trying to write a bash script that takes a file and passes each line from the file into an array with elements separated by column. For example: Sample file "file1.txt": 1 name1 a first 2 name2 b second 3 name3 c third and have arrays such as: line1 = ( "1" "name1" "a"... (3 Replies)
Discussion started by: ShiGua
3 Replies

4. Shell Programming and Scripting

insert dummy values in a file

Hey guys, i have a file a.txt and i need to insert a dummy data into it as per the below pattern.. bash: cat a.txt 1234,34 3434,45 4545,56 3434,56 Now i need the file in the below pattern 1234,34,a0001,C_01 3434,45,a0002,C_02 4545,56,a0003,C_03 3434,56,a0004,C_04 here the count of... (3 Replies)
Discussion started by: jaituteja
3 Replies

5. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

6. Shell Programming and Scripting

Finding BEGINNING & ENDING positions of sequentially increasing sublists from a perl numeric array

I have got an Perl array like: @array = (1,2,3,4,5,6,1,2,3,4,1,2,1,2,3,4,5,6,7,8,9...............) This numeric sequence will be always sequentially increasing, unless it encounters, The beginning of the new sequentially increasing numeric sequence. SO in this array we get sequentially... (5 Replies)
Discussion started by: teknokid1
5 Replies

7. Shell Programming and Scripting

Read a input file and insert it to UDB sequentially

Guys, I'm very new to Unix script. I need to add some logics into the existing script. Read a record 1) if it's a header record then verify the file sequence no aginst the file sequence no in UDB control table. 2) if Step 1 is ok then CONNECT UDB otherwise stop or abend. 3) if... (0 Replies)
Discussion started by: Sunny TK Sun
0 Replies

8. Shell Programming and Scripting

saving values in file in an array in awk

hi i am trying to save values in a file in an array in awk..the file is as follows: 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, so far i have this: awk 'BEGIN {RS="\n";FS=","} { for(i=1;i<=NR;i++) { for(j=1;j<=NF;j++) { a=$j; } } (4 Replies)
Discussion started by: npatwardhan
4 Replies

9. UNIX for Dummies Questions & Answers

How to store the values in a file into an array

Hi, I do have a file and the contents are as follws: 10 20 30 40 50 Now I want to store those values into an array. How can be done this ?? (3 Replies)
Discussion started by: risshanth
3 Replies

10. UNIX for Advanced & Expert Users

insert pipe in file to separate values

hi all... i need your help, because i donīt know what to do... i have a flat file like this: B065200512312004123111010000061451 000021853 B065200512312004123111020000621907 000417802 B065200512312004123111030000005214 000005861 B065200512312004123111040000120133 000088448 and i need... (5 Replies)
Discussion started by: DebianJ
5 Replies
Login or Register to Ask a Question