Greping a string for only one occurence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping a string for only one occurence
# 8  
Old 07-24-2007
Oups ! My command print line with two occurence of the string !

Code:
sed -n '/the_string/{s/the_string//2;t;p;}' inputfile

Jean-Pierre.
# 9  
Old 07-24-2007
Aigles, ran your solution:
Code:
sed -n '/the_string/{s/the_string//2;t;p;}' inputfile

And received an error message:
Code:
Too many {'s

# 10  
Old 07-24-2007
Hi Every body
This is pinky new to forums
# 11  
Old 07-24-2007
urgent

Hi
Can any body help
I am writing a shell script and the parameter through command line is
orderlink=20
I am tring to get the substring
Example
String is orderlink=20 and I wanted to have substring after "="
my new string should be 20
The input string can be different as integration=15

Thnaks in advance
# 12  
Old 07-25-2007
Quote:
Originally Posted by Shell_Life
Aigles, ran your solution:
Code:
sed -n '/the_string/{s/the_string//2;t;p;}' inputfile

And received an error message:
Code:
Too many {'s

This command works fine with GNU sed.
I tried the command on my AIX box, and i get the same error than you.
The t sub-command of sed interprets all that follows as being a label.

The following syntax is accepted on AIX :
Code:
sed -n -e '/the_string/{s/the_string//2;t' -e 'p;}' inputfile

Jean-Pierre.
# 13  
Old 07-25-2007
Quote:
Originally Posted by pinky
Hi
Can any body help
I am writing a shell script and the parameter through command line is
orderlink=20
I am tring to get the substring
Example
String is orderlink=20 and I wanted to have substring after "="
my new string should be 20
The input string can be different as integration=15

Thnaks in advance
Welcome to the forums Smilie

Quote:
Urgent
This is not encouraged.

As a start looking for something like this,
Code:
val=`echo "orderlink=20" | sed 's/^.*=//g'`



Actually this should have been a new thread Smilie

Last edited by matrixmadhan; 07-25-2007 at 10:07 AM.. Reason: new thread ...
# 14  
Old 07-25-2007
how abt this

Code:
>cat check
first abc string string
second def string
third string string string
fourth string


If searchstring is "string"

Code:
awk -F"string" 'NF - 1 == 1 { print }' check

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get nth occurence of string from a file

I have file in which the data looks like this, 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ 03,test1,41203016,,/ 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ ... (16 Replies)
Discussion started by: r@v!7*7@
16 Replies

2. Shell Programming and Scripting

Greping the string from a log

Hi Folks, I am searching something in multiple logs , actually an even ocuurs which get recorded in logs with a special word so rite now I am opening an individual log in vi and then searching it but total in the directory there are such 15 logs and it is very difficult to go one by one so... (1 Reply)
Discussion started by: punpun66
1 Replies

3. UNIX for Dummies Questions & Answers

View 5 lines after the last occurence of a string

Hi Everyone, I am looking for the unix command by which I can view 5 lines after the last occurence of a string (including the last occurence) Example : I have the following lines in a unix file. I have to look for the last occurence of the string "How are you" and then view the next 5... (5 Replies)
Discussion started by: kannanfile
5 Replies

4. UNIX for Dummies Questions & Answers

View 10 lines after the 1st occurence of a string

Hi Everyone, I am looking for the unix command by which I can view 10 lines after the 1st occurence of a string (including the 1st occurence) Example : I have the following lines in a unix file. I have to look for the 1st occurence of the string "How are you" and then view the next 10 lines... (3 Replies)
Discussion started by: kannanfile
3 Replies

5. UNIX for Dummies Questions & Answers

To find the Nth Occurence of Search String

Hi guys, I like to find the Line number of Nth Occurence of a Search string in a file. If possible, if it will land the cursor to that particualar line will be great. Cheers!! (3 Replies)
Discussion started by: mac4rfree
3 Replies

6. Shell Programming and Scripting

Extract a string up to the first occurence of a substring

Hi, I'm a newbie to shell scripting and have searched the forum but couldn't find what i was looking for. Basically I have a list of filenames like... 123-fileone.txt I want to be able to extract the prefix up to the first '-'. So I'd end up with 123. I have attempted it using a pretty... (2 Replies)
Discussion started by: kirkg
2 Replies

7. Shell Programming and Scripting

greping last occurrence of the searched string

Hello, I have active log file i want to grep the last occurrence of the word in that log file the log file gets on increasing and increasing i want to fetch it from live file. Please guide me, Thanks in advance (4 Replies)
Discussion started by: vidurmittal
4 Replies

8. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies

9. Shell Programming and Scripting

How to find vowel's occurence in a string

Hi All, I want to search the string for vowel's occurence and find the no of occurence of each vowels, Could anyone help me out? This is urgent to me...I m new to Shell programming.. Thanks and Regards, Nids:b: (4 Replies)
Discussion started by: Nidhi2177
4 Replies

10. Shell Programming and Scripting

Replace string B depending on occurence of string A

Depending upon the occurence of string 'xyz', I want to remove -t from the input file. There is not a fixed length input file. Any suggestions Input file: this is xyz line -t of the data this is line 2 of -t of the data xyz this is line 3 of -t the file this is line xyz of the -t file... (1 Reply)
Discussion started by: hemangjani
1 Replies
Login or Register to Ask a Question