Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

URGENT! Please see question posted in UNIX Language...

Does anyone in here know UNIX, please see my question posted in UNIX if you can help me!!!!
Thanks
appreciative
0
appreciative
Asked:
appreciative
  • 9
  • 5
1 Solution
 
appreciativeAuthor Commented:
.... the more I try to figure it out, the more I get mixed up.... is there anyone out there who can help me???
appreciative
0
 
appreciativeAuthor Commented:
tried to sleep...can't...!!!  I have to make this script work...!!!  is there anyone still up at this hour who can help me????
appreciative
0
 
pagladasuCommented:
Could help you. However, couldn't find your question. Could you also post it here.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
appreciativeAuthor Commented:
Thank you, I'll get it right away
appreciative
0
 
appreciativeAuthor Commented:
HELP!!!  I have done most of the coding except for step 2 (all mixed up) and the name
of the files that have been concatenated do not display on screen, the script does not function as it should ... can someone please check and advise me of what I'm doing
wrong...!!!  Thank you!!!  I know I should do a "shift" because the script takes the destination as a file to be concatenated...but I don't know how to code a shift or where to place it in my script...
Thank you!!!
appreciative

    Scenario:
    I have to write a shell script that will concatenate the contents of multiple files into a        new file (called Groups).  This script should be written in two steps:

    Step1:
    . All filenames are to be supplied on the command line.
    . Validate the script's usage:  Make sure that the proper amount of arguments are             supplied on the command line.
    . The first argument will be the name of the destination file and all remaining arguments       will represent the name(s)   of the source file(s) to be added to the destination file.
    . At the end fo the script's execution, a report listing all files concatenated and all files        that were not concatenated   (because they do not exist) should be displayed.
    . The report format is to be the same as the given example (see below).
    . This script always appends if the destination already exists.

    Suppose the following files exist with the following file contents:
    Group1          Group2                    Concat1 (contents of 1st step)
    Alan              Chester                   Concat2 (contents of 2nd step)
    Andrea          Cassandra
    Bob               Dave
    Barbara          Diane

    Output format should be identical to:

    # concat1 Groups Group1 Group2
    The following files have been added to Groups:
       Group1 Group2 (indent of 3 spaces before Group1 and 1 space between Group1 and                                Group2)
    # cat Groups
    Alan
    Andrea
    Bob
    Barbara
    Chester
    Cassandra
    Dave
    Diane

    (no display of list of files that were not added, if such a list does not exist)


    Step2:
    . All the criteria implemented in the first step (except for   last one).
    . If the destination file exists, the script will ask the user to make a choice to either Overwrite or Append
    (O/A) to   the existing file.

    Output Format:

    #> concat2 Groups Group1
    Groups already exists, what do you want to do? (O/A)
    O (user answer)
    Overwriting Groups
    The following files have been added to Groups:
       Group1 (indent of 3 spaces)

    # cat Groups

    Alan
    Andrea
    Bob
    Barbara
    #

       
    My code up to now:

    FILES="$FILES `ls -aF|grep -v /|grep -v @`"
    DEST="Groups"
    DISPLAY=" " 
    NODISPLAY=" " 

    if ["$#"="0"]
    then
       echo "Please supply all file names."
    else
       echo "$# file(s) may be concatenated."
       for oneFile in $*
       do
          if [ -f $oneFile ]
          then
             cat $oneFile>>DEST
             else
               echo "Cannot concatenate...file does not exist."
          fi
       done
    fi

    for oneFile in $*
    do
       if [ -w $oneFile ]
       then
          DISPLAY="$DISPLAY $oneFile"
       else
          NODISPLAY="$NODISPLAY $oneFile"
       fi
    done

    echo "The following files have been added to $DEST:"
    echo $DISPLAY>PRINT
    echo "$PRINT"
    echo "The following files have not been added to $DEST:"
    echo $NODISPLAY>NOPRINT
    echo "$NOPRINT"
    #rm PRINT NOPRINT #commented this line out (I'm not sure I should do this!!)

    errors given:

    unix-conted:~/CONCAT$ Concat1 DEST Group1
    ./Concat1: [2=0]: command not found
    2 file(s) may be concatenated.
    cat: DEST: input file is output file
    The following files have been added to Groups:

    The following files have not been added to Groups:

    unix-conted:~/CONCAT$

    (also, I don't understand why it counts DEST as a file which can be concatenated, it should not, its the
    destination!!!)






0
 
pagladasuCommented:
Just got your listing. Taken a printout. Work on it and get back later.

0
 
appreciativeAuthor Commented:
Thank you so much....

0
 
appreciativeAuthor Commented:
pagladasu...are you still with me...???

0
 
pagladasuCommented:
Yep! I am here.
Most of your script is OK with some basic mistake
like
if [ "$#"="0" ]
remember 1 space before and after the '=' sign in all tests. No spaces in assignments
another one:
cat oneFile>>DEST should be
cat oneFile>>$DEST
Anyway, I had fiddled around a bit and perhaps this may help you.
#modified script begins
DEST="Groups"
DISPLAY=""
NODISPLAY=""
#you made a small mistake - a space before and after = is needed
#in testing for equality , should not be used in assignment statements
if [ $# = 0 ]
then
  echo "Please supply all file names"
else
  DEST=$1
  shift         ##needed to remove the target file from list
  if [ $# = 0 ]
  then
     echo "No files to concatenate in $DEST"
  else
     echo "$# files to be concatenated"
     for oneFile in $*
     do
      if [ -f $oneFile ]
      then
         cat $oneFile >> $DEST
         DISPLAY="$DISPLAY $oneFile"
      else
         echo "Cannot concatenate $oneFile - does not exist"
         NODISPLAY="$NODISPLAY $oneFile"
      fi
     done
     echo "Following files added to $DEST"
     echo $DISPLAY
     echo "Following have not been added"
     echo $NODISPLAY
  fi
fi
#modified script ends
Thanks and best of luck.
pagladasu

For any other clarifications catch me at my email no:
espical@hotmail.com

0
 
pagladasuCommented:
As above
0
 
appreciativeAuthor Commented:
Thanks more than a million  Pagladasu, I'll make the changes and run it... a little later 'cause I have to run now..

THANKS,
HAVE A GREAT DAY!!!!
  :- )={   }<

extremely more than,
appreciative








0
 
appreciativeAuthor Commented:
Thanks more than a million  Pagladasu, I'll make the changes and run it... a little later 'cause I have to run now..
(Sorry, I don't have many points... and know I probably will have more questions later)

THANKS,
HAVE A GREAT DAY!!!!
  :- )={   }<

extremely more than,
appreciative








0
 
pagladasuCommented:
Thank you for your appreciative appreciations.
0
 
appreciativeAuthor Commented:
My pleasure...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now