Delete lines if word found in file coderinme

Delete lines if word found in file coderinme

Delete lines if word found in file coderinme
Let us now code a new program so that it performs the following task:
Write a shell script which will delete all the lines containing the word unix in the files supplied as arguments to this shell script. Here, make sure that lines containing “unix” are deleted.

#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 file1 [file2 ...]"
exit 1
fi
replace="unix"
for i in "$@"; do
wordc=`grep -c "$replace" "$i"`
while read j; do
echo ${j//"$replace"/""}
done < $i > /tmp/temp.txt
cat /tmp/temp.txt > $i
echo -n "Number of replacements of "
tput bold
echo -n "'$replace'"
tput sgr0
echo -n " in "
tput bold
echo -n "'$i'"
tput sgr0
echo " are: "$wordc
done

For more programs in shell, visit our Shell Coder Archives

delete lines if word found

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without prior written permission of website admin, except in case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi

Leave a reply:

Your email address will not be published.