The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Formatting Output dhanamurthy Shell Programming and Scripting 6 05-02-2008 11:43 AM
Formatting mirusnet Shell Programming and Scripting 3 01-06-2008 11:38 PM
formatting tamemi UNIX for Dummies Questions & Answers 5 07-21-2002 09:03 AM
formatting xeron UNIX for Dummies Questions & Answers 5 03-20-2002 11:33 AM
formatting darryll777 UNIX for Dummies Questions & Answers 1 03-04-2002 01:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2003
cdunavent cdunavent is offline
Registered User
  
 

Join Date: Sep 2001
Location: D.C.
Posts: 54
Formatting using awk

Let's say I write a simple script that contains the following:

date | awk '{print $1}'
date | awk '{print $2}'

Of course, when I run the script the output will look similar to:

Tue
Mar

What if I want my ouput to be on one line as follows:

Tue Mar

What changes would I need to make to my script (#!/bin/csh)?

THanks

-cd
  #2 (permalink)  
Old 03-18-2003
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
date | awk '{print $1" "$2}'

will do what you asked for - of course, there are lots of different ways to do this (especially if you still want to keep two separate date commands)

#!/bin/csh
set d1=`date | awk '{print $1}'`
set d2=`date | awk '{print $2}'`
echo "$d1 $d2"
exit

Of course, you are then using up computing power doing a command twice...

#!/bin/csh
date +"%a %h"
exit
  #3 (permalink)  
Old 03-18-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
You can just use field descriptors with the date command to achieve the same result:

date +"%a %b"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0