I have this csh script and I need to write this code in AWK language. But I've no idea how. Can somebody pls help?
unset v
unset l
set histchars=""
while ( $#argv > 0 )
switch ( $argv[1] )
case -h :
if ( $?v || $?l ) break
echo "test.csh"
echo "Usage: $0:t [-h] [-v <size>] [-l] [dir1 dir2 ...]"
echo " -h : this help"
echo " -v <size> : search files bigger than <size>"
echo " -l : work with lines, not bytes"
echo " dir1 dir2 ... : directories to proceed"
exit 0
breaksw
case -v :
shift argv
if ( $#argv == 0 ) then
echo "Error: <size> expected" > /dev/stderr
exit 1
endif
set v = $1
expr $v + 0 >& /dev/null
if ( ( $status != 0 ) || ( $v:q < "0" ) ) then
echo "Error: $v:q":" not correct value" >/dev/stderr
exit 1
endif
shift argv
breaksw
case -l :
shift argv
set l
breaksw
default:
break
endsw
end
if ( $#argv == 0 ) set argv = ( $argv "$cwd:q" )
foreach dir ($argv)
if (! -e $dir:q ) then
echo "Error: $dir:q":" Cannot access directory" >/dev/stderr
continue
endif
if ( `echo "$dir:q" | cut -c1` != "/" ) set dir = "$cwd:q/$dir:q"
set dirs = "`find "$dir:q" -type d`"
foreach subdir ($dirs:q)
if (! $?l ) then
set files = "`ls -la "$subdir:q" | tail +4 | awk '{ print "\$"5"\,\$"NF }' | sort -rg`"
if ( $#files == 0 ) continue
if (! $?v ) then
set file = ( $files[1] )
while (! -f $subdir:q/$file[2] )
shift files
set file = ( $files[1] )
end
if ($#files > 0 ) echo "Output: '$subdir:q/$file[2]:q $file[1]:q'"
else
while ( $#files > 0 )
set file = ( $files[1] )
if ( ( -f $subdir:q/$file[2] ) && ( $file[1] > $v ) ) echo "Output: '$subdir:q/$file[2]:q $file[1]:q'"
shift files
end
endif
else
set files = "`ls -a "$subdir:q"`"
shift files
shift files
if ( $#files == 0 ) continue
set subory = ()
while ( $#files >0 )
if (`file $subdir:q/$files[1]:q | awk '{ print index($0,"text") }'` != "0") set subory = ( $subory:q "`cat $subdir:q/$files[1]:q | wc -l` $subdir:q/$files[1]:q" )
shift files
end
if ( $#subory == 0 ) continue
if (! $?v ) then
set max = ( $subory[1] )
shift subory
while ( $#subory >0 )
set file = ( $subory[1] )
if ( $file[1] > $max[1] ) set max = ( $subory[1] )
shift subory
end
echo "Output: '$max[2]:q $max[1]:q'"
else
while ( $#subory > 0 )
set file = ( $subory[1] )
if ( $file[1] > $v ) echo "Output: '$file[2]:q $file[1]:q'"
shift subory
end
endif
endif
end
end
unset v
unset l
set histchars=""
while ( $#argv > 0 )
switch ( $argv[1] )
case -h :
if ( $?v || $?l ) break
echo "test.csh"
echo "Usage: $0:t [-h] [-v <size>] [-l] [dir1 dir2 ...]"
echo " -h : this help"
echo " -v <size> : search files bigger than <size>"
echo " -l : work with lines, not bytes"
echo " dir1 dir2 ... : directories to proceed"
exit 0
breaksw
case -v :
shift argv
if ( $#argv == 0 ) then
echo "Error: <size> expected" > /dev/stderr
exit 1
endif
set v = $1
expr $v + 0 >& /dev/null
if ( ( $status != 0 ) || ( $v:q < "0" ) ) then
echo "Error: $v:q":" not correct value" >/dev/stderr
exit 1
endif
shift argv
breaksw
case -l :
shift argv
set l
breaksw
default:
break
endsw
end
if ( $#argv == 0 ) set argv = ( $argv "$cwd:q" )
foreach dir ($argv)
if (! -e $dir:q ) then
echo "Error: $dir:q":" Cannot access directory" >/dev/stderr
continue
endif
if ( `echo "$dir:q" | cut -c1` != "/" ) set dir = "$cwd:q/$dir:q"
set dirs = "`find "$dir:q" -type d`"
foreach subdir ($dirs:q)
if (! $?l ) then
set files = "`ls -la "$subdir:q" | tail +4 | awk '{ print "\$"5"\,\$"NF }' | sort -rg`"
if ( $#files == 0 ) continue
if (! $?v ) then
set file = ( $files[1] )
while (! -f $subdir:q/$file[2] )
shift files
set file = ( $files[1] )
end
if ($#files > 0 ) echo "Output: '$subdir:q/$file[2]:q $file[1]:q'"
else
while ( $#files > 0 )
set file = ( $files[1] )
if ( ( -f $subdir:q/$file[2] ) && ( $file[1] > $v ) ) echo "Output: '$subdir:q/$file[2]:q $file[1]:q'"
shift files
end
endif
else
set files = "`ls -a "$subdir:q"`"
shift files
shift files
if ( $#files == 0 ) continue
set subory = ()
while ( $#files >0 )
if (`file $subdir:q/$files[1]:q | awk '{ print index($0,"text") }'` != "0") set subory = ( $subory:q "`cat $subdir:q/$files[1]:q | wc -l` $subdir:q/$files[1]:q" )
shift files
end
if ( $#subory == 0 ) continue
if (! $?v ) then
set max = ( $subory[1] )
shift subory
while ( $#subory >0 )
set file = ( $subory[1] )
if ( $file[1] > $max[1] ) set max = ( $subory[1] )
shift subory
end
echo "Output: '$max[2]:q $max[1]:q'"
else
while ( $#subory > 0 )
set file = ( $subory[1] )
if ( $file[1] > $v ) echo "Output: '$file[2]:q $file[1]:q'"
shift subory
end
endif
endif
end
end