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
sed string manipulation speedieB Shell Programming and Scripting 4 11-23-2008 08:27 PM
string manipulation james6 UNIX for Dummies Questions & Answers 5 06-03-2008 10:05 AM
String Manipulation Help shadow0001 Shell Programming and Scripting 4 03-09-2008 04:35 PM
string manipulation Cactus Jack Shell Programming and Scripting 9 02-14-2008 01:14 PM
string manipulation hai1973 Shell Programming and Scripting 13 08-20-2007 11:27 AM

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 08-09-2006
zoo591 zoo591 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 20
awk string manipulation

Here is my awk code in a shell script:

localRecDir=/somedirectory/
#
awk -v LRD="$localRecDir" '{out = sprintf ("%s0000000%s"),LRD,substr($3,4) ; print > out; close(out)}' *.log

Here is the contents of my *.log file I am trying to parse with my script:

000007 0110 07-0001583
000007 0110 07-0001584
000007 0110 07-0001585

I am expecting my script to:
1) get the 3rd field of my log file.
2) strip off the "07-" from the 3rd field
3) use sprintf to format a "pathname" to the "out" variable.
Essentially, I am trying to create 3 files:

/somedirectory/00000000001583
/somedirectory/00000000001584
/somedirectory/00000000001585

But I get this error:
awk: Syntax error
at line 1 of program << {out = sprintf ("%s0 ... >>
context is
{out = sprintf >>> ("%s0000000%s"), <<<
awk: illegal statement
at line 1 of program << {out = sprintf ("%s0 ... >>

Can someone please point out what I am doing incorrectly.

TIA
zoo591
  #2 (permalink)  
Old 08-09-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
you have mis-balanced ')'-s for your 'sprintf'
Code:
out = sprintf ("%s0000000%s",LRD,substr($3,4))
  #3 (permalink)  
Old 08-09-2006
zoo591 zoo591 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 20
Thumbs up

Quote:
Originally Posted by vgersh99
you have mis-balanced ')'-s for your 'sprintf'
Code:
out = sprintf ("%s0000000%s",LRD,substr($3,4))
Thank you vgersh99. That was exactly the problem.
The script now works as intended.
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 01:55 PM.


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