Search word in file and print coderinme

Search word in file and print coderinme

Search word in file and print coderinme
Let us now code a program so that it performs the following task: The word unix is present in only some of the files supplied as arguments to the shell script. Your shell script should search each of these files in turn and stop at the first file that it encounters containing the word unix. This filename should be displayed on the screen.

if [ $# -lt 2 ]; then
echo "Usage: $0 file1 file2 [file3 ...]"
exit 1
for i in "$@"; do
(grep -q "$search" "$i")
if [ $? -eq "0" ]; then
echo -n "The word "
tput bold
echo -n "'$search'"
tput sgr0
echo -n " is found in the file "
tput bold
echo "'$i'"
tput sgr0

For more programs in shell, visit our Shell Coder Archives

search word in file and print

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 Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me

Leave a reply:

Your email address will not be published.