0

I am a beginner for shell script, and I want to know how to check the content of file using if condition

I have a files content .txt and what I want is

if content of file have .txt; then
skip
else
run code
fi

4
Contributors
3
Replies
9
Views
5 Years
Discussion Span
Last Post by Snadiger
0

Hello,

The first real question is what do you mean by content? Are you implying that it is a file containing only text or that it has the file extension .TXT?

And second is this real shell scripting in Linux, OSX and Unix, or Semi-scripting in Windows shell or VB?

0


To check whether the content of the file contains the string .txt:

file=content.txt
string=.txt
if grep -q "$string" "$file"
then
  : ## skip (i.e. do nothing)
else
  : do whatever
fi

To check whether a filename ends in .txt, use case:

file=whatever
case $file in
     *.txt) ;; # do nothing
     *) : do whatever ;;
esac
0

Hi,

I am beginner to shell scripts,and i want to know about checking the contents of shell scripts file which ends with the extension .ksh or .sh.

How we have to check the contents of those ready scripts used for execution purpose.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.