check contents of file - Shell Scripting

This is a discussion on check contents of file - Shell Scripting ; I am a beginner for shell script, can somebody tell me 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: check contents of file

  1. check contents of file

    I am a beginner for shell script, can somebody tell me 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

  2. Re: check contents of file

    Quote Originally Posted by zulabc View Post
    I am a beginner for shell script, can somebody tell me 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
    Really sorry but I am a little confused on exactly what you are looking for. You say you want to check the content of a file and that you have a file with "content .txt", does this mean you have a file that contains ".txt" in it? or do you have a file with the ending of .txt (e.g. test.txt)?

    A little more information, and sample files, would be helpful

  3. Re: check contents of file

    hi

    I am new to scripts too but maybe can be helpful to you...

    did you mean something like that:
    Code:
    #!/bin/bash
    FILE=$ ( ls -l | grep *.txt )
    
    if [ -f $FILE ];
    then
       echo "File $FILE exists."
    else
       echo "File $FILE does not exist."
    fi

+ Reply to Thread