![]() |
|
|
|
|
|||||||
| 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 |
| How to split a value according to character position | michaeltravisuk | UNIX for Dummies Questions & Answers | 4 | 05-27-2008 04:07 AM |
| search in finding position of a string in avariable | smr_rashmy | Shell Programming and Scripting | 2 | 02-08-2008 07:58 PM |
| Counting position of a character | rochitsharma | UNIX for Advanced & Expert Users | 3 | 11-27-2007 03:26 PM |
| Sorting a flat file based on multiple colums(using character position) | cucubird | Shell Programming and Scripting | 8 | 07-24-2006 09:47 PM |
| Character position | akrathi | UNIX for Dummies Questions & Answers | 4 | 10-26-2005 01:06 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Finding character position in file
Hi all,
how to find a character position in a word/line Eg. Unix forum is the best site. Now in above line i want to find the character 'x' position i.e 4 As in oracle we can make use of 'instr' function to do this. Is their any thing in Unix shell script ? Thanks In advance. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
my way of doing it:
$ echo "Unix forum is the best site." | grep -o "[-_a-zA-Z0-9\.]" | grep -n x |
|
#3
|
|||
|
|||
|
Thanks
but it give output as 4:x I nt it to be 4 |
|
#4
|
|||
|
|||
|
$ echo "Unix forum is the best site." | grep -o "[-_a-zA-Z0-9\.]" | grep -n x | cut -d: -f1
|
|
#5
|
|||
|
|||
|
Thanks a lot
Quote:
|
|
#6
|
|||
|
|||
|
Or use the expr command with 'index' :
To return the first position of where any characters in the string "de" is found in "abcdef", enter: expr index abcdef de The following is displayed: 4 cheers |
|||
| Google The UNIX and Linux Forums |