Awk help with populating variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk help with populating variable
# 1  
Old 08-11-2008
Awk help with populating variable

Hi,

I'm looking for help trying to parse a data stream. Any help would be greatly appreciated.

Quote:
I need the awk statment to retrieve the entire date "Aug 3 00:00:02 2008" and then populate the "a" variable. Currently I am only populating it with $2 or "Aug".

Any I thoughts on how I can populate variable "a" with the entire line or date?

Thanks!
JMD
My awk statement is

Code:
awk '/Aug/{a=$2}/vol/{print a, host, $1, $2, $3, $4, $5}' out.txt

Sample Data Stream "out.txt"

-----------------------------

# Aug 3 00:00:00 2008

===== DF =====
Filesystem kbytes used avail capacity Mounted on
/vol/vol1/ 781441232 285519024 495922208 37% /vol/vol1/
/vol/vol2/ 781441232 320075968 461365264 41% /vol/vol2/


# Aug 3 00:00:02 2008

===== DF =====
Filesystem kbytes used avail capacity Mounted on
/vol/vol1/ 2495490048 1738484048 757006000 70% /vol/vol2/
/vol/vol2/ 8734215168 7250720128 1483495040 83% /vol/vol2/


Quote:
What i'm getting from the above awk statement:
Aug /vol/vol2/ 781441232 320075968 461365264 41% /vol/vol2/
Aug /vol/vol1/ 2495490048 1738484048 757006000 70% /vol/vol2/
Aug /vol/vol2/ 8734215168 7250720128 1483495040 83% /vol/vol2/

-------------

Thanks!
# 2  
Old 08-11-2008
awk -F"#" '/Aug/ {print $2}' out.txt
# 3  
Old 08-11-2008
Hi "sudhamacs"

Any way I can get the data to look like this?

I need the date printed on the same line with the data. for example

Code:
Aug  3 00:00:00 2008 /vol/vol2/ 781441232 320075968 461365264 41% /vol/vol2/
Aug  3 00:00:00 2008 /vol/vol1/ 2495490048 1738484048 757006000 70% /vol/vol2/
Aug  3 00:00:00 2008 /vol/vol2/ 8734215168 7250720128 1483495040 83% /vol/vol2/

# 4  
Old 08-11-2008
Code:
awk '/Aug/{a=$0}/vol/{print a, host, $1, $2, $3, $4, $5}' out.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help in populating output in table using shell scripting

Below is my code where i tried using table tag to print out put in table but its not working #!/bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1";... (5 Replies)
Discussion started by: ankit.mca.aaidu
5 Replies

2. Programming

Populating Lists in Def using Python

Dipping around in python again and need to create a def that will populate a list(content) with the files that os.walk finds from within this directory and then I will re.search through each files looking for content. In learning Python, can someone point me in the right direction. This is what I... (3 Replies)
Discussion started by: metallica1973
3 Replies

3. UNIX for Dummies Questions & Answers

Help populating double quotes using awk

Want to populate double quotes for each filed using awk: Input: cat file.txt => "1-23-test_test1-test2" Required output : "1-23-test_test1-test2"|"#GT_properties_xyz" Was trying the below command on solaris 9 machine : awk -F"|" '{print $1"|""#GT_properties_xyz"}' file.txt ... (8 Replies)
Discussion started by: rajachandhok
8 Replies

4. Programming

Populating Associate Arrays in PHP

I'm not very good at associative arrays; and working on this PHP code has got me a bit stumped. My goal is to populate a (multidimensional) associative array in a PHP while look after a MySQL query. The code fragment looks like this: while($campaign_row = mysql_fetch_array($campaigninfo)) { ... (9 Replies)
Discussion started by: Neo
9 Replies

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

6. Programming

populating a JList

Hi, I have to create a JList and the items I need to display are store in HashMap table. What would be the easiest way to populate this JList. Basically the items I want to display/show in the JList are the key values of the HashMap. Thanks in advance for any suggestions. (0 Replies)
Discussion started by: arizah
0 Replies

7. Shell Programming and Scripting

awk - Pre-populating an array from system command output

So, here's a scenario that requires the same logic as what I'm working on: Suppose that you have a directory containing files named after users. For awk's purposes, the filename is a single field-- something parse-friendly, like john_smith. Now, let's say that I'd like to populate an array in... (2 Replies)
Discussion started by: treesloth
2 Replies

8. Shell Programming and Scripting

Populating an Array

Guys, I need to iterate populate an array while going over files in directory. Can someone please tell me syntax I tried this but it isn't working ==> for F in `ls -p "${directory1}" | grep -v "\/"` do cd "${directory2}" cmp "${directory2}"/"${F}" "${directory1}"/"${F}" ... (2 Replies)
Discussion started by: Veenak15
2 Replies

9. Shell Programming and Scripting

Populating array raised an error

Hi, The following test case populate an array named: array3. Since array1 and array2 are equal in length and values array3 will remain empty. #!/usr/bin/ksh test() { set -A array1 "A" set -A array2 "A" NUM_1=`echo ${#array1}` print "num elenemt in NUM_1 is ${NUM_1}" i=1 for ELE2 in... (1 Reply)
Discussion started by: yoavbe
1 Replies

10. Shell Programming and Scripting

populating array using awk

Hi. I have a file with the following structer: DB DISK LOCATION SIZE ============================================ PROD DATA_01 /dev/dm-23 10 PROD DATA_02 /dev/dm-24 10 PROD DATA_03 /dev/dm-25 10 DEV DATA_04 /dev/dm-26 10 DEV DATA_05 ... (1 Reply)
Discussion started by: yoavbe
1 Replies
Login or Register to Ask a Question