Commit fc28484d authored by ONKAR PIYUSH PRPADEEP's avatar ONKAR PIYUSH PRPADEEP

Upload new file

parent c902d4bd
#!/bin/bash
if [ "$2" == "-lines" ]
then
{
lines=$(( $(grep -c ^ $1) ))
echo "$lines lines"
}
elif [ "$2" == "-words" ]
then
{
grep -E -o '\b\w+\b' $1 > output
awk '/$/!p {count++}END{if(count!=0){print count,"words"}else{print "0 words";}}' output
rm output
}
elif [ "$2" == "-chars" ]
then
{
grep -E -o '(\S)' $1 > charac
awk '/$/!p {count++}END{if(count!=0){print count,"characters"}else{print "0 characters";}}' charac
rm charac
}
elif [ "$2" == "-paras" ]
then
{
#sed -n '/^$/N;/^\n$/D' $1
#awk '{if(!$0)count++}END{if(count!=0){print count,"paragraphs"}else{print "0 paragraphs";}}' $1
sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' $1 > file1
grep -cvP '\S' file1 > z
line1=$(head -n 1 z)
r=$(($line1+1))
echo "$(( $r-3 ))"
rm z
rm file1
}
else
{
grep -E -o '\S' $1 > charac
awk 'BEGIN {ORS=" "}/$/!p {count++}END{if(count!=0){print count,"characters,"}else{print "0 characters,";}}' charac
rm charac
grep -E -o '\b\w+\b' $1 > output
awk 'BEGIN {ORS=" "}/$/!p {count++}END{if(count!=0){print count,"words,"}else{print "0 words,";}}' output
rm output
lines=$(( $(grep -c ^ $1) ))
echo -n "$lines lines, "
#sed -n '/^$/N;/^\n$/D' $1
sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' $1 > file1
grep -cvP '\S' file1 > z
line1=$(head -n 1 z)
r=$(($line1+1))
echo "$(( $r-3 )) paragraphs"
rm z;rm file1
#awk '{if(!$0)count++}END{if(count!=0){print count,"paragraphs"}else{print"0 paragraphs";}}' $1
}
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment