![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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, |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
If your shell supports this type of expansion (and ksh 93 should):
Code:
line="123356572867116w1671716"
actual_length = 16
cut_line=${line:0:$actual_length}
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|