|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc. |
![]() |
|
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Many Thanks FM!
I am almost done with the following code (thanks also to another no-awk guy here Code:
#!/bin/bash
c=/path/
cd $c
#crop bad elements between "small area" and "P R O B L E M"
awk 'BEGIN{RS="--"}/'"P R O B L E M S I Z E"'/{for(i=1;i<=NF;i++)if($i == "NO"){n=i-1;print $n}}' DAT.dat > BAD.dat
while read line
do
P="$line"
echo $P
(echo "/Element, type"; echo ":/[0-9]"; echo "/$P/d";echo "wq!")|ex -s INPUT.inp
done < BAD.dat
There is only one problem left, when the BAD elements appear as second third or fourth item in the line--> in this case the line should not be deleted: Code:
*Element, type=DC2D3 432,477,478,479 433,439,481,482 --> line NOT to be deleted 434,483,484,440 --> line NOT to be deleted 435,486,485,484 436,487,488,489 437,490,491,492 438,493,488,487 439,494,488,493 --> line to be deleted 440,495,496,497 --> line to be deleted 441,491,498,496 442,496,498,497 443,493,499,494 444,500,487,501 445,500,493,487 446,493,500,499 447,499,500,498 448,502,503,504 449,505,506,507 450,508,507,509 451,506,509,507 452,510,511,512 453,510,506,505 454,510,513,506 455,514,505,515 *Elset, elset=C
|
|
||||
|
edit
If you change the print to.. Code:
{print "*Element" "\n" FILENAME}
|
|
|||
|
Hello,
thanks for suggestion but I still prefer the echo "/string" style with loop. I solved my problem above just adding ^ before $P. This code does exactly what I wanted but for just a single file: Code:
#!/bin/bash
c=/path/
cd $c
#crop bad elements between "small area" and "P R O B L E M"
awk 'BEGIN{RS="--"}/'"P R O B L E M S I Z E"'/{for(i=1;i<=NF;i++)if($i == "NO"){n=i-1;print $n}}' DAT.dat > BAD.dat
while read line
do
P="$line"
echo $P
(echo "/Element, type"; echo ":/[0-9]"; echo "/^$P/d";echo "wq!")|ex -s INPUT.inp
done < BAD.dat
making this code recursive on several files is the next challenge now (part II) Thanks! |
|
|||
|
Sorry that I couldn't help earlier but sometimes I have to work at work.
Anyway is not what I would have like the script to be like (I was thinking of a awk complete solution, but time was not on my side. Just to help get over with the last step here is the script you have and I added just a loop to do multiple files(assuming they are in the same directory. #!/bin/bash #c=/path/ #cd $c #crop bad elements between "small area" and "P R O B L E M" awk 'BEGIN{RS="--"}/'"P R O B L E M S I Z E"'/{for(i=1;i<=NF;i++)if($i == "NO"){n=i-1;print $n}}' A.dat > BAD.dat all_files="/home/dan/progr_task/*.inp" for the_file in $all_files; do echo "$the_file is my file" while read line do P="$line" # echo $P (echo "/Element, type"; echo ":/[0-9]"; echo "/^$P/d";echo "wq!")|ex -s $the_file done < BAD.dat done |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|