Solved

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

Posted on 1998-11-22
14
204 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
how to convert c++ code to Android App 3 110
Best book to learn C++ 4 85
c++ reading data from file into two dimensional array 3 117
Coding for the first time 9 37
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

821 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