Skip to content

Instantly share code, notes, and snippets.

@mukeshgurpude
Last active December 27, 2021 11:24
Show Gist options
  • Select an option

  • Save mukeshgurpude/fee646bc4e741625c9d3ad52c3ae6db8 to your computer and use it in GitHub Desktop.

Select an option

Save mukeshgurpude/fee646bc4e741625c9d3ad52c3ae6db8 to your computer and use it in GitHub Desktop.
OS-Lab Exercises
# iterate through jpg files in current directory
# and rename them to start with today's date
for file in $( ls *.jpg )
do
mv $file $(date +%F)-$file
done
# Delete the zero sized files in the current directory
find . -type f -size 0 -exec rm {} \;
# Remove duplicate lines from a file
#- Line numbers file
# Sort the file
# Remove duplicates
# sort according to line numbers
# Remove line numbers
file=$1;
cat -n $file > .a.tmp
sort -k 2 .a.tmp > .b.tmp
uniq -f 1 .b.tmp > .a.tmp
sort -n .a.tmp > .b.tmp
cut -f 2 .b.tmp > .a.tmp
echo "The file $file has been cleaned"
cat .a.tmp > $file
rm .a.tmp .b.tmp
echo "Cleaned file is: "
cat $file
duplicate
lines
here
lines
duplicate
line
here
with
duplicate
lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment