Dump an array in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dump an array in a file
# 1  
Old 08-30-2006
Data Dump an array in a file

Hi,
I'm wondering if there's a way to dump the content of an array into a specified part of a file.
I know that I can redirect the output in a way that the array adds in the text file, this is done with ">>", but doing by this way, puts the array at the end of the file, and I'm asking for some that make something like this:
#text file
something
another thing
one more thing

<put array here>

other thing
more things
#End of text file

array[1]=20501 string;
array[2]=20502 string;
etc..

Doing with ">>" results on:
#text file
something
another thing
one more thing

<put array here>

other thing
more things
20501 string;
20502 string;
etc..
#End of text file

And I want:
#text file
something
another thing
one more thing

20501 string;
20502 string;
etc..

other thing
more things
#End of text file

Last edited by IMD; 08-30-2006 at 08:00 PM..
# 2  
Old 08-30-2006
I've try with this but it doesn't work

for line in `cat algo.txt`
do
echo "$line" >> algo.txt.app.tmp
if [ $line = OTHER ]; then
OTHER_FLAG=1
fi
if [ $OTHER_FLAG = 1 && $line = "" ]; then
for ins in ${ins_array[*]}
do
echo " $ins SOCKETED;" >> algo.txt.app.tmp
done
OTHER_FLAG=0
fi
done
# 3  
Old 08-30-2006
And with AWK

I also try with AWK, but it doesn't accept array when you are passing parameters.

awk '{
print $0
if ( $1 == "OTHER" )
{
OTHER_FLAG = 1
}
if ( OTHER_FLAG && $0 = "" )
{
for ( i = 0; i <= array_size; i++ )
{
printf (" %6s SOCKETED;", array[i])
}
OTHER_FLAG = 0
}
}' array=${ins_array[*]} array_size=$ins_array_size algo.txt > algo.txt.ap
p.tmp
# 4  
Old 08-31-2006
Computer This Work perfectly

ins_array_count=1
while [ $ins_array_count -le $ins_array_size ]
do
ins_val=${ins_array[$ins_array_count]}
awk '{
print $0
if ( $1 == "OTHER" )
{
OTHER_FLAG = 1
}
if ( OTHER_FLAG && $0 == "" )
{
printf (" %6s SOCKETED;\n", ins_val)
OTHER_FLAG = 0
}
}' ins_val=$ins_val algo.txt > algo.txt.app.tmp
ins_array_count=`expr $ins_array_count + 1`
cp algo.txt.app.tmp algo.txt
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare file to array, replace with corresponding second array

ok, so here is the issue, I have 2 arrays. I need to be able to create a loop that will find ${ARRAY1 in the text doc, and replace it with ${ARRAY2 then write the results. I already have that working. The problem is, I need it to do that same result across however many items are in the 2... (2 Replies)
Discussion started by: gentlefury
2 Replies

2. UNIX for Dummies Questions & Answers

dump display to a file

Hi: I want to dump whatever command I type on the terminal + whatever is the result of that command's execution to one file. Is it possible in unix? Rgds, Indu (3 Replies)
Discussion started by: indu_shr
3 Replies

3. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

4. Programming

Best way to dump metadata to file: when and by who?

Hi, my application (actually library) indexes a file of many GB producing tables (arrays of offset and length of the data indexed) for later reuse. The tables produced are pretty big too, so big that I ran out of memory in my process (3GB limit), when indexing more than 8GB of file or so.... (9 Replies)
Discussion started by: emitrax
9 Replies

5. UNIX for Advanced & Expert Users

converting openssl hex dump or PEM format to integer array

Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
Discussion started by: jhopper
1 Replies

6. UNIX for Dummies Questions & Answers

How to restore a dump file on the disk

Hi all, i am a real dummy to unix and in need of help.My platform is Sun solaris(5.9) I have a dump file, an oracle cold backup taken with ufsdump command. This dump file resides on the disk, not the tape. I want to extract this dump file to a directory. But i cant, i read about ufsrestore... (1 Reply)
Discussion started by: merope
1 Replies

7. Programming

How to use a core dump file

Hi All, May be it is a stupid question, but, I would like to know what is the advantage using a core dump file at the moment of debugging using gdb. I know a core dump has information about the state of the application when it crashed, but, what is the difference between debugging using the... (2 Replies)
Discussion started by: lagigliaivan
2 Replies

8. UNIX for Dummies Questions & Answers

core dump file size

Hi All, is there any way to find out the optimal/would be size of the cor dump file generated by the system while a process got terminated abnormally? Basically we have been asked to provide the size of the core dump file being generated by the administrators who maintained the UNIX boxes.... (4 Replies)
Discussion started by: pushp.gahlot
4 Replies

9. Shell Programming and Scripting

Importing dump file

Hi, I am trying to import 22 .dmp files but facing the problem with the last table file it never ends the import command, only the table is created but the rows of the table don't get imported. This is the problem with only ine table rest 21 tables are being imported properly. Thanks in... (2 Replies)
Discussion started by: anushilrai
2 Replies

10. UNIX for Dummies Questions & Answers

help, what is the difference between core dump and panic dump?

help, what is the difference between core dump and panic dump? (1 Reply)
Discussion started by: aileen
1 Replies
Login or Register to Ask a Question