Solved

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

Posted on 1998-11-22
14
213 Views
Last Modified: 2012-05-04
Does anyone in here know UNIX, please see my question posted in UNIX if you can help me!!!!
Thanks
appreciative
0
Comment
Question by:appreciative
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
14 Comments
 

Author Comment

by:appreciative
ID: 1178438
.... 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
 

Author Comment

by:appreciative
ID: 1178439
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178440
Could help you. However, couldn't find your question. Could you also post it here.
0
Industry Leaders: 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!

 

Author Comment

by:appreciative
ID: 1178441
Thank you, I'll get it right away
appreciative
0
 

Author Comment

by:appreciative
ID: 1178442
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178443
Just got your listing. Taken a printout. Work on it and get back later.

0
 

Author Comment

by:appreciative
ID: 1178444
Thank you so much....

0
 

Author Comment

by:appreciative
ID: 1178445
pagladasu...are you still with me...???

0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178446
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
 
LVL 4

Accepted Solution

by:
pagladasu earned 20 total points
ID: 1178447
As above
0
 

Author Comment

by:appreciative
ID: 1178448
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
 

Author Comment

by:appreciative
ID: 1178449
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178450
Thank you for your appreciative appreciations.
0
 

Author Comment

by:appreciative
ID: 1178451
My pleasure...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question