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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get substr? syamkp Shell Programming and Scripting 6 03-30-2008 11:08 PM
awk or substr ramky79 UNIX for Dummies Questions & Answers 3 03-13-2007 05:18 PM
Substr deepakwins UNIX for Dummies Questions & Answers 9 02-13-2007 09:58 PM
How to use awk substr ? sabercats Shell Programming and Scripting 1 02-10-2006 04:01 PM
awk substr? MizzGail Shell Programming and Scripting 2 03-14-2003 10:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 6
substr not working

Hi I am trying to run this command in ksh ...its not working

$line="123356572867116w1671716"
actual_length = 16
cut_line=`awk 'BEGIN{print substr(ARGV[1],1,actual_length)}' "$line"`
the substr is not giving me an output

how can i make it done
can anyone hwlp me on this

cut_line=`awk 'BEGIN{print substr(ARGV[1],1,16)}' "$line"`

This is working ...But I want variable to be passed instead of numeric
please guide me

Thanks,
Reply With Quote
Forum Sponsor
  #2  
Old 05-10-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 736
Code:
$line="123356572867116w1671716"
cut_line=`awk -v v=${#line} 'BEGIN{print substr(ARGV[1],1,v)}' "$line"`

Last edited by danmero; 05-10-2008 at 10:37 PM.
Reply With Quote
  #3  
Old 05-10-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
If your shell supports this type of expansion (and ksh 93 should):

Code:
line="123356572867116w1671716"
actual_length = 16
cut_line=${line:0:$actual_length}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0