![]() |
|
|
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 |
| Korn: How to loop through a string character by character | shew01 | Shell Programming and Scripting | 10 | 12-02-2008 07:58 AM |
| converting character string to hex string | axes | High Level Programming | 5 | 09-20-2006 02:04 PM |
| Sed character number specification | mvalonso | UNIX for Dummies Questions & Answers | 4 | 05-10-2006 11:32 AM |
| defining a variable as a number or character? | noobian | UNIX for Dummies Questions & Answers | 1 | 04-26-2005 09:19 PM |
| Number or Character | j1yant | Shell Programming and Scripting | 3 | 02-10-2003 02:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Pulling the first and last character/number from a string.
Let's say I have a word "foobar23" in a file, and I want to pull the first "f" and last "3" character out of the world, how would I accomplish that?
# cat file foobar23 I want the output to be: f3 |
|
||||
|
(use the button right of the post (attention sign) to report the spam) bash: Code:
> cat file
foobar23
> var=`cat file`
> echo $var
foobar23
> echo ${var:0:1}${var: -1}
f3
Note that the space in ${var: -1} is important. Last edited by fabtagon; 06-17-2008 at 11:37 AM.. Reason: damn ;-) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|