I have a file of the following format:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data3 size 154
datag
datas
datat
datar
datas
datap
$data4 size 234
datat
datat
datap
datai
so that certain line begin with $ and have the parameter "size". I want to delete the entire block of data of the lines for which "size" > 200.
In my case the output would be:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data4 size 234
datat
datat
datap
datai
Any ideas? Thanks
Assuming you want the blocks with a size > 200:
awk '/^\$/{f=$NF>200?1:0}f' file
No, the size of the blocks does not match the parameter "size". What I want is to delete the block of data from one $ to the next, IF the parameter "size" is >200
But your desired output contains only blocks of > 200:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data4 size 234
datat
datat
datap
datai
Sorry, misunderstanding.
I only want to keep the blocks for which the first line contain "size 'number' " where number >200.
But the number of rows for each block could also be less than 200
felipead:
Sorry, misunderstanding.
I only want to keep the blocks for which the first line contain "size 'number' " where number >200.
But the number of rows for each block could also be less than 200
Have you tried the provided code?
awk '/^\$/{f=$NF>200?1:0}f' file
Hi,
sed -e '/size \(1\{,1\}[0-9]\{,2\}\|200\)$/,/size \(20[1-9]\|2[1-9][0-9]\|[3-9][0-9][0-9]\|[1-9][0-9]\{3,\}\)/{/size \(20[1-9]\|2[1-9][0-9]\|[3-9][0-9][0-9]\|[1-9][0-9]\{3,\}\)/!d;}' file
Regards.
Soham
October 24, 2013, 4:25pm
9
I would take a simpler script
#! /bin/ksh
flag=0
while read line
do
lin=`print $line | sed -n '/.data.*size/p`
if [[ -n $lin ]]
then
num=`print $lin | sed 's/.data.*size //'`
if [[ $num -gt 200 ]]
then
flag=1
else
flag=0
fi
fi
if [[ $flag -eq 1 ]]
then
print $line
fi
done < file1