![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|||
| Google UNIX.COM |