![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 |
| check position of end of line(URGENT PLS) | evvander | Shell Programming and Scripting | 6 | 11-11-2007 01:46 PM |
| check position of end of line for some specific lines | senthil_is | Shell Programming and Scripting | 1 | 11-08-2007 09:19 PM |
| how to check a word in a file and assign to a variable | hippo2020 | Shell Programming and Scripting | 1 | 06-28-2007 09:00 AM |
| Change Position of word character | cedrichiu | Shell Programming and Scripting | 6 | 03-11-2007 09:52 PM |
| Can a shell script pull the first word (or nth word) off each line of a text file? | tricky | Shell Programming and Scripting | 5 | 08-17-2006 03:29 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How to check a word position in a file ?
Hello everybody,
I have a file like this : "window 1 truck 3 duck 2... fire 1... etc..." and I would like to print the following number of a word I am searching for. (For example here, if I search for the word "fire", I will print "1") Thank you for your help ! |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
Code:
sed 's/.* fire \([0-9][0-9]*\) .*/\1/' file |
|
|||
|
Quote:
The sed statement has a <space> after the \) bracket. It should be Code:
# sed 's/.* fire \([0-9][0-9]*\).*/\1/' file 1 |
|
|||
|
But the above pattern will also catch words like backfire, spitfire etc...
|
|||
| Google UNIX.COM |