![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep throws in dashes? | kingdbag | UNIX for Dummies Questions & Answers | 3 | 04-27-2007 04:18 PM |
| Alternatives for CLOCK_MONOTONIC | amitks21 | UNIX for Advanced & Expert Users | 3 | 11-17-2006 04:09 AM |
| fwrite throws segmentation fault | fermisoft | High Level Programming | 6 | 09-13-2005 01:46 AM |
| ASP alternatives | Ricki | UNIX for Dummies Questions & Answers | 3 | 05-30-2001 05:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Substr throws an ERROR. Any alternatives?
Can somebody please help me to remove the last character of a string.??
I have a string variable, in which I dynamically put values in a for loop.I want to remove the last character from the string. But, the problem is I will not know which character can come in the string (Its inside for loop). So I tried using substr. substr does not work here. Is there any alternative to do this?? Here my code goes. .... for files in $rawSourceFiles loop MID_INFILE=`cat “${files}” | grep “Message-Id:"` len=`expr “${MID_INFILE}” : ‘.*’` len=`expr $len - 1` trimmedMID_INFILE=`expr substr “${MID_INFILE}” 1 ${len}` ..... ... done But, it does not seem working. It throws an error “expr: syntax error” .. What all I want here is in trimmedMID_INFILE should be the string MID_INFILE with last character trimmed. (last char could be anything like "\n", "/", etc.) Can anybody please enlighten me?? I would be so grateful. Thanks in advance. |
|
||||
|
Considering the ''expr' error that you are getting is from the code where you are trying to 'trim', than use the following:
Code:
trimmedMID_INFILE=`echo $MID_INFILE | cut -b 1-$len` - cut -b (cut by byte) - 1-$len (from 1st byte till $len - considering $len is already length - 1) |
|
||||
|
Thank you..
Thanks Hemangjan.. !!! Thanks a lot.. It worked.. Yay...!!!
![]() One more question, if [ $a = $b ] then echo SUCCESS fi If I want to case-insensitive-compare these two variables, what should I use?/ Sorry to ask these dumb questions. I'm a newbie to SHELL SCRIPTING.. :-( |
|
||||
|
This link may help
how to make case insensitive checks???? |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|