The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use a core dump file lagigliaivan High Level Programming 2 05-26-2008 06:06 AM
how to break mysql dump sql file learnbash Shell Programming and Scripting 2 05-14-2008 02:39 AM
core dump file size pushp.gahlot UNIX for Dummies Questions & Answers 4 08-06-2007 07:56 AM
Importing dump file anushilrai Shell Programming and Scripting 2 03-20-2006 02:56 AM
help, what is the difference between core dump and panic dump? aileen UNIX for Dummies Questions & Answers 1 06-11-2001 05:08 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-30-2006
IMD IMD is offline
Registered User
 

Join Date: Aug 2006
Posts: 5
Unhappy 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 04:00 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-30-2006
IMD IMD is offline
Registered User
 

Join Date: Aug 2006
Posts: 5
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
Reply With Quote
  #3 (permalink)  
Old 08-30-2006
IMD IMD is offline
Registered User
 

Join Date: Aug 2006
Posts: 5
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
Reply With Quote
  #4 (permalink)  
Old 08-31-2006
IMD IMD is offline
Registered User
 

Join Date: Aug 2006
Posts: 5
Talking 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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0