shell scripting - Unix

This is a discussion on shell scripting - Unix ; hi, I new to shell programming. I'm doing a small program in which i'm going through file and getting some data from it. My code snippnet is.. #!/bin/ sh if [ ! -f $1 ]; then echo "File: $1 isn't ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: shell scripting

  1. shell scripting

    hi,
    I new to shell programming.
    I'm doing a small program in which i'm going through file and getting
    some data from it.
    My code snippnet is..
    #!/bin/
    sh

    if [ ! -f $1 ]; then
    echo "File: $1 isn't a file"
    exit
    fi
    for n in `grep -n $ $1 | awk -F ':' '{print $1}'`
    do
    LINE=`head -$n $1|tail -1`
    # fetch the first n chars from
    line
    CHARS=`echo $LINE | cut -c 0-$2`
    # do whatever with
    CHARS
    echo $CHARS
    done
    It is givving error when i execute it .
    [/user/Myhome]sh file1
    : not found
    ' unexpectedntax error at line 9 : `do

    I googled for the answer but nothing promising..
    I want to read the file line by line and put the required data to
    another file.
    How should i do it??

    Thanx in advance.


  2. Re: shell scripting

    ruds writes:
    > hi,
    > I new to shell programming.
    >
    > I'm doing a small program in which i'm going through file and getting
    > some data from it.
    >
    > My code snippnet is..
    >
    > #!/bin/
    > sh
    >
    > if [ ! -f $1 ]; then
    > echo "File: $1 isn't a file"
    > exit
    > fi
    > for n in `grep -n $ $1 | awk -F ':' '{print $1}'`
    > do
    > LINE=`head -$n $1|tail -1`
    > # fetch the first n chars from
    > line
    > CHARS=`echo $LINE | cut -c 0-$2`
    > # do whatever with
    > CHARS
    > echo $CHARS
    > done
    > It is givving error when i execute it .
    > [/user/Myhome]sh file1
    > : not found
    > ' unexpectedntax error at line 9 : `do


    The script you have posted seems to have at least *some* strange layout
    and formatting errors. I'm not sure if it was Google's web UI which
    broke the formatting of the shell script, but it's definitely broken.

    For instance, these two lines:

    #!/bin/
    sh

    will *not* really work.

    There are other bugs in the script too, but I'm not sure how many of the
    minor buglets are caused by the web UI or are really in the script.

    Please try posting a plain text version of the shell script, using a
    client which doesn't mutilate what you write :-/


  3. Re: shell scripting

    ruds wrote:
    > hi,
    > I new to shell programming.
    > I'm doing a small program in which i'm going through file and getting
    > some data from it.


    Try this:
    http://open.itworld.com/5040/nls_uni...08/page_1.html

    --
    --------------------
    Ivan Novick
    http://www.0x4849.net

+ Reply to Thread