Find the answer to your Linux question:
Results 1 to 4 of 4
hi, i m getting segmentation fault on the 25th line could any one help me with it #!/bin/sh -f dir=$(date +%d-%m-%y) echo $dir Y=$(find ./$dir -type d|wc -l) if [ ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Location
    bangalore
    Posts
    38

    segmentation fault

    hi,
    i m getting segmentation fault on the 25th line could any one help me with it
    #!/bin/sh -f
    dir=$(date +%d-%m-%y)
    echo $dir
    Y=$(find ./$dir -type d|wc -l)
    if [ $Y -eq 0 ];then
    mkdir $dir
    fi
    name=$1

    arg=$@
    echo $arg
    echo $name
    suffix=_0
    suffix1=_
    X=$(find ./$dir -type f|grep $name$suffix*|wc -l)
    ROBIN=$X
    echo $ROBIN
    echo $X
    if [ $ROBIN -lt 9 ];then \
    ROBIN=`expr $ROBIN + 1`; touch ./$dir/$name$suffix$ROBIN.csv; ./card ./$dir/$name$suffix$ROBIN.csv $arg
    else
    ROBIN=`expr $ROBIN + 1`; touch ./$dir/$name$suffix1$ROBIN.csv
    ./card ./$dir/$name$suffix1$ROBIN.csv $arg
    fi
    find ./$dir -type f -printf '%f %c\n'|grep $name$suffix*|sort -rk5|awk '{print $1}'

  2. #2
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by robinsonvpanicker View Post
    hi,
    i m getting segmentation fault on the 25th line could any one help me with it
    #!/bin/sh -f
    dir=$(date +%d-%m-%y)
    echo $dir
    Y=$(find ./$dir -type d|wc -l)
    if [ $Y -eq 0 ];then
    mkdir $dir
    fi
    name=$1

    arg=$@
    echo $arg
    echo $name
    suffix=_0
    suffix1=_
    X=$(find ./$dir -type f|grep $name$suffix*|wc -l)
    ROBIN=$X
    echo $ROBIN
    echo $X
    if [ $ROBIN -lt 9 ];then \
    ROBIN=`expr $ROBIN + 1`; touch ./$dir/$name$suffix$ROBIN.csv; ./card ./$dir/$name$suffix$ROBIN.csv $arg
    else
    ROBIN=`expr $ROBIN + 1`; touch ./$dir/$name$suffix1$ROBIN.csv
    ./card ./$dir/$name$suffix1$ROBIN.csv $arg
    fi
    find ./$dir -type f -printf '%f %c\n'|grep $name$suffix*|sort -rk5|awk '{print $1}'
    What pattern are you grep-ing for? Why use a '*'?

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Location
    bangalore
    Posts
    38
    Quote Originally Posted by scm View Post
    What pattern are you grep-ing for? Why use a '*'?
    i m searching for a list of files of the same name in a directory.......eg:XA12C_01,XA12C_02,XA12C_03,XA12 C_04, XB12C_01,XB12C_02,XB12C_03,XC12C_01.............th ats y i m grepping grep $name$suffix* for the similar files and taking their count and incrementing it to make a new file...eg: if number of files for XA12C is 4 then the new file created will b XA12C_05

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by robinsonvpanicker View Post
    i m searching for a list of files of the same name in a directory.......eg:XA12C_01,XA12C_02,XA12C_03,XA12 C_04, XB12C_01,XB12C_02,XB12C_03,XC12C_01.............th ats y i m grepping grep $name$suffix* for the similar files and taking their count and incrementing it to make a new file...eg: if number of files for XA12C is 4 then the new file created will b XA12C_05
    Okay, but you do realise that the * in a regular expression matches zero or more occurrences of the preceding character, so if your $suffix holds an underscore, and $name holds "XA12C", then you'll actually be matching all names with XA12C anywhere in them (beginning, middle or end).

    Also be aware that the shell will try to use that * before it passes the argument to grep, so if you've got any filenames that begin with "XA12C" in the directory you're running the command from then grep will see that list of names, and not the pattern - it'll take the first name as the pattern and the rest of the list as the files to search, disregarding stdin completely!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...