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
FTP and run a loop for array problem tuffgong2008 Shell Programming and Scripting 3 12-19-2008 04:56 PM
Reading from while loop into an array ssuresh1999 UNIX for Dummies Questions & Answers 2 08-12-2008 11:53 AM
Array in loop is acting up RisingSun Shell Programming and Scripting 5 08-07-2008 02:21 PM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
Array Declaration and For Loop 33junaid Shell Programming and Scripting 4 09-15-2007 04:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2009
vincyoxy vincyoxy is offline
Registered User
  
 

Join Date: Mar 2009
Location: Singapore
Posts: 12
Exclamation Help with awk in array in while loop

Hi everyone
I have 2 files - IN & OUT. Example:

IN
A:13:30
B:45:40
.
.
. UNLIMITED

OUT
Z:12:24
Y:20:15
.
.
. UNLIMITED


I want first row of numbers of IN - OUT. Example 13-12 45-20
My code is

#!/bin/csh -f
set y=1
while ( $y<UNLIMITED )
set in = `awk -F':' '{print $2}' IN |awk '{array[NR]=$0} END {print array[y];}'`
set out = `awk -F':' '{print $2}' OUT |awk '{array[NR]=$0} END {print array[y];}'`
set number = `expr $in - $out`
echo "$number"
@ y = $y + 1
end

expr: syntax error
expr: syntax error
expr: syntax error
expr: syntax error
expr: syntax error
expr: syntax error
all is expr: syntax error
I tried to solve more than one day already. And also duno wat should i write instead of UNLIMITED.
Anyone can help me?
  #2 (permalink)  
Old 03-19-2009
wabard wabard is offline
Registered User
  
 

Join Date: Mar 2009
Location: Adelaide, SA & Perth, WA - Australia
Posts: 25
Exclamation

As a starting point, you may want to review the following, AWK program

Files are read into a two-dimensional array and then processed for printing.


The original query was to extract the 5th column from multiple files and print them out in columnar format.
  #3 (permalink)  
Old 03-19-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,320
Quote:
Originally Posted by vincyoxy View Post
Hi everyone
I have 2 files - IN & OUT. Example:

IN
A:13:30
B:45:40
.
.
. UNLIMITED

OUT
Z:12:24
Y:20:15
.
.
. UNLIMITED


I want first row of numbers of IN - OUT. Example 13-12 45-20
My code is

Please put code inside [code] tags.
Quote:
Code:
 
#!/bin/csh -f
csh is not recommended for scripting.
Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
Quote:
Code:
set y=1
while ( $y<UNLIMITED )
set in = `awk -F':' '{print $2}' IN |awk '{array[NR]=$0} END {print array[y];}'`
set out = `awk -F':' '{print $2}' OUT |awk '{array[NR]=$0} END {print array[y];}'`
set number = `expr $in - $out`
echo "$number"
@ y = $y + 1
end

Code:
cut -d: -f2 in > in.tmp
cut -d: -f2 out > out.tmp
paste -d- in.tmp out.tmp
rm in.tmp out.tmp
Sponsored Links
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 11:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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