How to check a word position in a file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check a word position in a file ?
# 8  
Old 01-04-2008
Computer

Thanks for pointing that out. This should lay such issues to rest:

Code:
$ cat file
 window 0 truck 3 duck 2 spitfire 8 fire 1 backfire 9
$ sed 's/.*\<fire\> \([0-9][0-9]*\).*/\1/' file
1
$ sed 's/.*\<spitfire\> \([0-9][0-9]*\).*/\1/' file
8
$ sed 's/.*\<window\> \([0-9][0-9]*\).*/\1/' file
0
$ sed 's/.*\<backfire\> \([0-9][0-9]*\).*/\1/' file
9

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

Write a word at 72nd position of a matched line in a file

Hi, I need to search a file for a pattern,replace some other word and write a word at its 72nd position. For example, My name is Mano.Im learning Unix. I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And... (5 Replies)
Discussion started by: mano1 n
5 Replies

3. Shell Programming and Scripting

Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do grep "....TX" file The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea Example: test1 car... (5 Replies)
Discussion started by: e_mikey_2000
5 Replies

4. UNIX for Dummies Questions & Answers

Word check within file

I am trying to see if a word exists within the file, then do command accordingly. cmd=$(grep -ci "$word" $file) if ; then echo "Word exists" else echo "Word does not exist." fiI try this code, but it keeps giving me syntax errors for the cmd line. Am I doing something... (3 Replies)
Discussion started by: itech4814
3 Replies

5. Shell Programming and Scripting

Need to check a file from a certain position and date onwards

Hi Guys, I need some advice please. My script is not grabbing information from a text file from a certain date correctly. It seems to be grabbing everying in the file, i know it is something simple but i have looked to hard and to long, to know what the issue is. Script awk '... (9 Replies)
Discussion started by: Junes
9 Replies

6. Shell Programming and Scripting

Need to check a file from a certain position onwards

Scripting Guru's, I need your help, can you tell me how i can check a file from a certain point onwards via a ksh script. Currerntly i am checking the whole file and can't script it so it checks from 17.01.2012 20:00:00 onwards please.. Any help will be greatly appericated. See file... (10 Replies)
Discussion started by: Junes
10 Replies

7. UNIX for Dummies Questions & Answers

Script to delete a word based on position in a file

Hi, I am new to unix. I want to delete 2 words placed at position say for example at 23rd and 45th position in a line. I used sed but couldnt achieve this. Example: the file contains 2 lines 12345 98765 "12345" 876 12345 98765 "64578" 876 I want to delete " placed at position 13 and 19... (4 Replies)
Discussion started by: nbks2u
4 Replies

8. Programming

C++ > check if a file contains a word...

I wanna check if a file located in /home/user/.config/Home/unkilled.txt contains the word 'permitted'... I am a beginner in C++. This is my code: 1. #include <stdio.h> 2. #include <cerrno> 3. #include <sys/stat.h> 4. #include <fstream> 5. #include <sys/types.h> 6. #include... (1 Reply)
Discussion started by: hakermania
1 Replies

9. Shell Programming and Scripting

How to put a word starting at particular position in a file using shell scripting

Hi all, I'm new to shell scripting and hence this query. I have 2 files. temp.txt and config.txt. The values in temp.txt are tab separated. ex: temp.txt AB CDE GHIJ OPQRS WXY ex:config.txt (1st line for 1st element of temp.txt and so on) start = '1' end='5' start = '6' end =... (26 Replies)
Discussion started by: subhrap.das
26 Replies

10. UNIX for Dummies Questions & Answers

Paste a word in the third field position of a file

Hi All, I have a file like this, 0.0.0.1 /account 327706,Data Cleansing,,,CRM error,100,0 The above line is a comma separted data file. I want to modify the third field to The final data file should be like 0.0.0.1 /account 327706,Data Cleansing,,,CRM error,100,0 ... (1 Reply)
Discussion started by: girish.raos
1 Replies
Login or Register to Ask a Question
FFS(3)							     Linux Programmer's Manual							    FFS(3)

NAME
ffs, ffsl, ffsll - find first bit set in a word SYNOPSIS
#include <strings.h> int ffs(int i); #define _GNU_SOURCE #include <string.h> int ffsl(long int i); int ffsll(long long int i); DESCRIPTION
The ffs() function returns the position of the first (least significant) bit set in the word i. The least significant bit is position 1 and the most significant position is, for example, 32 or 64. The functions ffsll() and ffsl() do the same but take arguments of possibly different size. RETURN VALUE
These functions return the position of the first bit set, or 0 if no bits are set in i. CONFORMING TO
ffs():4.3BSD,POSIX.1-2001. The ffsl() and ffsll() are glibc extensions. NOTES
BSD systems have a prototype in <string.h>. SEE ALSO
memchr(3), feature_test_macros(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2009-08-27 FFS(3)