columns

columns

Post by Tri Tr » Thu, 27 Feb 1997 04:00:00



        I was wondering how do you get the columns out of the output?  For
example, using the cal program, I get the output

      February 1997      
Sun Mon Tue Wed Thu Fri Sat  
                         1
 2   3   4   5   6   7   8
 9  10  11  12  13  14  15
16  17  18  19  20  21  22
23  24  25  26  27  28

I was wondering how I can get the column for Wed only?  Any help would be
appreciated.  Thank you.

--
-----------------------------------------------------------------
Tri Tram, Computer Science and Engineering at UCLA
http://www.seas.ucla.edu/~tram

 
 
 

columns

Post by Anurag Gupta HSS-Indi » Thu, 27 Feb 1997 04:00:00



>         I was wondering how do you get the columns out of the output?  For
> example, using the cal program, I get the output

>       February 1997
> Sun Mon Tue Wed Thu Fri Sat
>                          1
>  2   3   4   5   6   7   8
>  9  10  11  12  13  14  15
> 16  17  18  19  20  21  22
> 23  24  25  26  27  28

> I was wondering how I can get the column for Wed only?  Any help would be
> appreciated.  Thank you.

> --
> -----------------------------------------------------------------
> Tri Tram, Computer Science and Engineering at UCLA
> http://www.seas.ucla.edu/~tram

cal | awk ' { print $4 } '
will give you the fourth column for Wed.

But then if you want to pick up first or second column this will also
give you "month" in first col and "year" in second col which are col
1 and 2 in that line.

If you want to getrid of them there could be other solutions.

cheers,

-Anurag

--
______________________________________________________________________

ANURAG GUPTA                               Fax: +91-124-342810, 342811
Hughes Software Systems, INDIA           Phone: +91-124-346666, 343703


 
 
 

columns

Post by Andreas Schw » Thu, 27 Feb 1997 04:00:00


|>   I was wondering how do you get the columns out of the output?  For
|> example, using the cal program, I get the output

|>       February 1997      
|> Sun Mon Tue Wed Thu Fri Sat  
|>                          1
|>  2   3   4   5   6   7   8
|>  9  10  11  12  13  14  15
|> 16  17  18  19  20  21  22
|> 23  24  25  26  27  28

|> I was wondering how I can get the column for Wed only?  Any help would be
|> appreciated.  Thank you.

cal | cut -cx-y

with appropriate values for x and y.
--
Andreas Schwab                                      "And now for something

 
 
 

columns

Post by Doug Barne » Thu, 27 Feb 1997 04:00:00



>         I was wondering how do you get the columns out of the output?  For
> example, using the cal program, I get the output

>       February 1997
> Sun Mon Tue Wed Thu Fri Sat
>                          1
>  2   3   4   5   6   7   8
>  9  10  11  12  13  14  15
> 16  17  18  19  20  21  22
> 23  24  25  26  27  28

> I was wondering how I can get the column for Wed only?  Any help would be
> appreciated.  Thank you.

> --
> -----------------------------------------------------------------
> Tri Tram, Computer Science and Engineering at UCLA
> http://www.seas.ucla.edu/~tram

awk would be what I's use:

cal|awk '{print $4}'

 
 
 

columns

Post by Jerry Crawfo » Thu, 27 Feb 1997 04:00:00



: |>         I was wondering how do you get the columns out of the output?  For
: |> example, using the cal program, I get the output
:  
: |>       February 1997      
: |> Sun Mon Tue Wed Thu Fri Sat  
: |>                          1
: |>  2   3   4   5   6   7   8
: |>  9  10  11  12  13  14  15
: |> 16  17  18  19  20  21  22
: |> 23  24  25  26  27  28

: |> I was wondering how I can get the column for Wed only?  Any help would be
: |> appreciated.  Thank you.

: cal | cut -cx-y

: with appropriate values for x and y.

Or,

cal | awk '{print $4}'

 
 
 

columns

Post by Doug Barne » Thu, 27 Feb 1997 04:00:00




> >         I was wondering how do you get the columns out of the output?  For
> > example, using the cal program, I get the output

> >       February 1997
> > Sun Mon Tue Wed Thu Fri Sat
> >                          1
> >  2   3   4   5   6   7   8
> >  9  10  11  12  13  14  15
> > 16  17  18  19  20  21  22
> > 23  24  25  26  27  28

> > I was wondering how I can get the column for Wed only?  Any help would be
> > appreciated.  Thank you.

> > --
> > -----------------------------------------------------------------
> > Tri Tram, Computer Science and Engineering at UCLA
> > http://www.seas.ucla.edu/~tram

> awk would be what I's use:

> cal|awk '{print $4}'

One other thing, this ONLY works if there are equal number of fields per
row.  AWK is looking for the 4th column, if there is NO 4th column on a
row, you have a problem.  You,ll either have to tell AWK what to do if a
row has less than 7 columns (i.e. the 1st and last rows typically).
 
 
 

columns

Post by Icarus Spar » Thu, 27 Feb 1997 04:00:00





>>         I was wondering how do you get the columns out of the output?  For
>> example, using the cal program, I get the output

>> I was wondering how I can get the column for Wed only?  Any help would be
>> appreciated.  Thank you.

>cal | awk ' { print $4 } '
>will give you the fourth column for Wed.

>But then if you want to pick up first or second column this will also
>give you "month" in first col and "year" in second col which are col
>1 and 2 in that line.

>If you want to getrid of them there could be other solutions.

cal | awk 'NR>1 { print $4 } '

Icarus

 
 
 

columns

Post by Dave A. La Ros » Fri, 28 Feb 1997 04:00:00



> If you want to getrid of them there could be other solutions.

> cal | awk 'NR>1 { print $4 } '

> Icarus

My 2 cents:
        cal | awk 'NF >= 4 { print $4}'
will only print out if 4 (or x) colums exists.

Hate to correct the 'master':-)
--

________________ http://www.icdc.delcoelect.com/Saber/ _________________

"The difference between theory and experiment is that in theory the
 experiment works."

________________________________________________________________________

 
 
 

columns

Post by Hartmut Schmi » Fri, 28 Feb 1997 04:00:00



> I was wondering how I can get the column for Wed only?

cal | tail +2  | cut -c10-12

--
Hartmut Schmidt

 
 
 

columns

Post by Ralf Becke » Sat, 01 Mar 1997 04:00:00




> > ....
> > I was wondering how I can get the column for Wed only?  Any help would be
> > appreciated.  Thank you.
> > ....

> cal | awk ' { print $4 } '
> will give you the fourth column for Wed.

> But then if you want to pick up first or second column this will also
> give you "month" in first col and "year" in second col which are col
> 1 and 2 in that line.
> ...

cal | awk '{ if (NR > 1) print $2 }'
use this, to ignore the first line in output of 'cal' and print out
the second column

Bye,
        Ralf

--
_______________________________________________________________________

 Ralf Becker - Studentischer Mitarbeiter im Rechenzentrum der FH Trier
             - Student der Angewandten Informatik, Anw: Elektrotechnik
             - Mitarbeiter der no|Software GmbH


 WWW : http://www.fh-trier.de/~beckerr    TELEFAX: +49 6563 930025
_______________________________________________________________________

 
 
 

columns

Post by Andreas Schw » Sat, 01 Mar 1997 04:00:00



|>>
|>> If you want to getrid of them there could be other solutions.
|>>
|>> cal | awk 'NR>1 { print $4 } '
|>>
|>> Icarus
|> My 2 cents:
|>   cal | awk 'NF >= 4 { print $4}'
|> will only print out if 4 (or x) colums exists.

But will fail as well if the colums are right aligned (as it is the case
with the first row).

$ cal 1 1996
   January 1996
 S  M Tu  W Th  F  S
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
$ cal 1 1996 | awk 'NF >= 4 { print $4}'
W
4
10
17
24
31
$ cal 1 1996 | cut -c10-12
y 1
 W
 3
10
17
24
31

|> Hate to correct the 'master':-)

Ditto.
--
Andreas Schwab                                      "And now for something

 
 
 

columns

Post by Geoff Cla » Sat, 01 Mar 1997 04:00:00



}: |>       February 1997      
}: |> Sun Mon Tue Wed Thu Fri Sat  
}: |>                          1
}: |>  2   3   4   5   6   7   8
}: |>  9  10  11  12  13  14  15
}: |> 16  17  18  19  20  21  22
}: |> 23  24  25  26  27  28
}: |> I was wondering how I can get the column for Wed only?
}: cal | cut -cx-y
}: with appropriate values for x and y.
}cal | awk '{print $4}'

This will work in this particular case, but it won't work for months that
start on a Wednesday (or Monday or Tuesday).

If you want the column for Saturday, using awk '{print $7}' will *only*
work for months that start on a Sunday.

The "cut" solution will work in all cases.
--

UniSoft Limited, London, England.

 
 
 

columns

Post by John Sava » Mon, 10 Mar 1997 04:00:00



>|>      I was wondering how do you get the columns out of the output?  For
>|> example, using the cal program, I get the output

>|>       February 1997
>|> Sun Mon Tue Wed Thu Fri Sat
>|>                          1
>|>  2   3   4   5   6   7   8
>|>  9  10  11  12  13  14  15
>|> 16  17  18  19  20  21  22
>|> 23  24  25  26  27  28

>|> I was wondering how I can get the column for Wed only?

cal 2 1997 |sed -n "2,$s/\(............\)\(...\).*/\2/p"

Explanation: from line two onwards skip the first twelve columns
and return the next three. This should work for even the oldest
versions of sed.

Alternatively, cal 2 1997 |awk '{if(NR>1) {print substr($0,13,3)}'
--
John Savage     koala ~ sydney.dialix.com.au     <-- use this address

 
 
 

1. sed/awk : need just the first column in a multi-column file


assuming you will have a space as the delimiter for your data ...
here it is in AWK.

AWK script would be ...
{ print $1 }

and then you would execute this on the command-line ...

AWK -f [script file] [data file] > output.file (if you want to save the
output)

note:  there are other elegent ways of doing the above, but this
        example is probably the easiest way to think about it.

-Bob-

Bob Angell                               | Data Integration (multi-platform)
Principal, Management Systems Engineer   | Health Systems Engineering
Applied Information & Management Systems | Database design/development
1238 Fenway Avenue - SLC, UT 84102-3212  | Simulation/Modeling/Neural Nets

     [Standard Disclaimer: Speaking for the University of Utah, NOT!]

2. * HELP *HOW CAN I SET **NOT** DEFAULT RESOLUTION AND REFRESH RATE

3. Newbie: adding and averaging columns, based on feature in column 2 (awk?)

4. Antec SCSI controller (sold by NEC for CD-ROM)

5. Sorting By Second Column With Unique First Column

6. Disk space for all pkgs?

7. AIX Script to Summarize By First Column By Adding Values in Numerical Columns

8. Using installer.coff for rescue, how???

9. arrange columns and find average of each column

10. setting 100-column & 132-column modes

11. SQL to compute sums (similar to SQL*plus break on <column> compute sum of <other_col> on <column>)

12. How To Transpose Row Into Column In A Text File ...

13. formatting columns in txt file