முதலில் டெர்மினலில்
sudo gedit delfi இங்கு delfi என்பது கோப்பின் பெயராகும். இது நம் விருப்பம் போல் அமைத்துக்கொள்ளலாம். இந்த கோப்பினை desktopல் செமித்துக்கொள்ளலாம். ஒரு உதாரணத்திற்கு.
இந்த கோப்பில் கீழ்கண்ட வரிகளை காப்பி செய்து பேஸ்ட் செய்ய வேண்டும்.
#!/bin/bash
# Write a shell script which deletes all even numbered line from a text file.
# -------------------------------------------------------------------------
file=$1
counter=0
out="oddfile.$$" # odd file name
if [ $# -eq 0 ]
then
echo "$(basename $0) file"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file!"
exit 2
fi
while read line
do
# find out odd or even line number
isEvenNo=$( expr $counter % 2 )
if [ $isEvenNo -eq 0 ]
then
# odd match; copy all odd lines $out file
echo $line >> $out
fi
# increase counter by 1
(( counter ++ ))
done < $file #
#remove input file
/bin/rm -f $file #
#rename temp out file
/bin/mv $out $file
பின்னர் டெர்மினலில்
sudo chmod +x delfi என்று தட்டச்சு செய்து scriptஐ இயங்ககூடிய நிலையில் வைக்கவேண்டும். பின்னர் ஒரு டெக்ஸ்ட் கோப்பினை தேர்ந்தெடுத்துக்கொள்ளவேண்டும். இங்கு நான் தேர்ந்தெடுத்தது கீழ்கண்ட கோப்பாகும்.

ஒரு உதாரணத்திற்கு மேலே உள்ள கோப்பினை தேர்ந்தெடுத்திருக்கிறேன். இந்த கோப்பிற்கு numb.txt என்று பெயர் கொடுத்துள்ளேன். இந்த scriptஐ இயக்குவதற்கு டெர்மினலில்
./delfi numb.txt என்று தட்டச்சு செய்தால் டெக்ஸ்ட் கோப்பில் உள்ள இரட்டை படை வரிகள் அழிந்துவிட்டிருக்கும்.

2 comments:
எளிமையாக சொல்லியுள்ளீர்கள்.
நன்றி வடுவூர் குமார்
Post a Comment