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
error: field has incomplete type boyanov High Level Programming 4 08-10-2007 05:15 AM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 04:20 AM
Correct the error plz Mandab Shell Programming and Scripting 2 05-11-2007 02:15 PM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 PM

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 06-20-2006
abbey abbey is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 2
Error : Field $() is not correct

Hi All,

I'm new to shell scripting. Trying to extract substring using awk script as shown below :

Flag=$1
Length=`echo ${#Flag}`
NewLen=$Length-2
NewFlag=`echo $Flag|awk '{print substr($Flag,0,$NewLen)}'`
echo "New string is : $NewFlag"
exit

When I execute this script the following error message appears :
awk: 0602-562 Field $() is not correct.
The input line number is 1.
The source line number is 1.

Could you please guide me to resolve this error.

Thanks in advance.
  #2 (permalink)  
Old 06-20-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
I think you are trying to extract a string by omitting the last two characters.

If so, you can do


Code:
${Flag%??}

  #3 (permalink)  
Old 06-20-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
In awk:

Code:
echo "New string is : $(echo|awk -v Flag=$1 '{print substr(Flag,0,length(Flag)-2)}')"

  #4 (permalink)  
Old 06-20-2006
abbey abbey is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 2
Thanks everyone for their prompt help!!!!
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 02:33 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