The UNIX and Linux Forums  


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
one question for bash shell script zx1106 Shell Programming and Scripting 9 03-10-2008 12:40 AM
Bash scripting question re: newlines retrovertigo Shell Programming and Scripting 4 07-06-2007 01:44 PM
Globbing slash Wildcarding Question scotbuff Shell Programming and Scripting 4 02-02-2007 12:10 AM
quick newbie bash question redsand9009 Shell Programming and Scripting 4 01-25-2007 03:44 AM
BASH shell script question ewarmour Shell Programming and Scripting 3 05-24-2002 06:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-14-2005
franzke franzke is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 1
awk / bash globbing question

I would like to process a list of files matching: GPS*\.xyz with an awk script. I would then like to output the files to GPS*\.xyz.out (e.g. the same file name appended with .out). Something like:

Code:
awk '{if(NR==1) {offset=-$1}; $1=$1+offset; print }' GPS*.xyz

this does exactly what I want EXCEPT redirecting the output appropriately. I tried

Code:
awk '{ ... print > FILENAME.out}' GPS*.xyz
and
awk '{...}' GPS*.xyz > GPS*.xyz.out

but as expected this did not work.

I realize that putting this in:
Code:
for f in ls GPS*.xyz

loop would work as I need but I would like an elegant solution that I can learn from.

Suggestions?

Cheers,
Brandon Franzke
  #2 (permalink)  
Old 07-14-2005
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Quote:
Originally Posted by franzke
I would like to process a list of files matching: GPS*\.xyz with an awk script. I would then like to output the files to GPS*\.xyz.out (e.g. the same file name appended with .out). Something like:

Code:
awk '{if(NR==1) {offset=-$1}; $1=$1+offset; print }' GPS*.xyz
Since you are reading several files, NR probably should be FNR:

Code:
awk 'FNR==1 {offset=-$1;next} {$1+=offset; print >FILENAME".out"}' PS*.xyz

  #3 (permalink)  
Old 07-14-2005
r2007's Avatar
r2007 r2007 is offline
Registered User
  
 

Join Date: Jun 2005
Location: China
Posts: 73

Code:
awk 'FNR==1 {offset=-$1;if(NR>1) close(of);of=FILENAME".out"} {$1+=offset; print >of}' GPS*.xyz

  #4 (permalink)  
Old 07-15-2005
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Quote:
Originally Posted by futurelet
Since you are reading several files, NR probably should be FNR:

Code:
awk 'FNR==1 {offset=-$1;next} {$1+=offset; print >FILENAME".out"}' PS*.xyz
close() may be needed to prevent having too many files open.

Code:
awk 'FNR==1 {offset=$1;close(f);f=FILENAME".out";next}{$1-=offset; print >f}' GPS*.xyz

The next is there becasue I assume you don't want the line with the offset to be printed.
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 08:46 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