Replacing a word after a matched pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing a word after a matched pattern
# 1  
Old 06-12-2008
Replacing a word after a matched pattern

Hello,

Actually i want to replace the word after a matched pattern.

For Ex:
lets say that i am reading a file line by line

while read line
do
echo $line
# i need to search whether a pattern exists in the file and replace the word after if the pattern exist.
# for example : $line=" this is a test line"
# $Pattern="is a"
echo "Enter a new value to replace the '"$Var1"' : "
read NwPat <&1
# i want to retrive $Var1="test" and replace it with a another pattern
# $NwPat which is provided as user input.
done < $INT_FILE


Any help would be useful.

Thanks

Rahul
# 2  
Old 06-12-2008
got the solution guys its TXT=`echo $line | sed -e 's/.* //'`

Thanks

rahul
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing the first word if the word three match

Dear ALL, I have sample file : IDcentos-forum,bash,linuxCentOS,GNome IEfedora-milis,cli,linuxRedhat,KDE IRfreebsd-milis,aix,unixbsd,pyton required output: centos,bash,linuxCentOS,GNome fedora,cli,linuxRedhat,KDE freebsd,aix,unixbsd,pyton Can you help me pls.. (1 Reply)
Discussion started by: gnulyn
1 Replies

2. Shell Programming and Scripting

Replacing matched patterns in multiple files with awk

Hello all, I have since given up trying to figure this out and used sed instead, but I am trying to understand awk and was wondering how someone might do this in awk. I am trying to match on the first field of a specific file with the first field on multiple files, and append the second field... (2 Replies)
Discussion started by: karlmalowned
2 Replies

3. Shell Programming and Scripting

Replacing a particular word with another word in all the xml's under a particular directory with sed

Hi Folks, Could you please advise what will be the SED command to replace a word in all xml's under a particular directory for example let say I rite now at the following below location $ cd /ter/rap/config now under config directory there will be lots of xml file , now my objective is to... (1 Reply)
Discussion started by: punpun66
1 Replies

4. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

5. Shell Programming and Scripting

Insert certain field of matched pattern line above pattern

Hello every, I am stuck in a problem. I have file like this. I want to add the fifth field of the match pattern line above the lines starting with "# @D". The delimiter is "|" eg > # @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q # @P... (5 Replies)
Discussion started by: jyu3
5 Replies

6. Shell Programming and Scripting

Grep word between matched pattern

would like to print word between matched patterns using sed for example : create INDEX SCOTT.OR_PK ON table_name(....) would like to print between SCOTT. and ON which is OR_PK Please help me out Thanks (4 Replies)
Discussion started by: jhonnyrip
4 Replies

7. Shell Programming and Scripting

start to print when a specified word is matched

Hello everybody, How can I start to print an output when a word hits the pattern space. for example: file.txt : first line second line third line fourth line ... cat file.txt > function "second" should print second line third line fourth line ... thanks for the replies now... (3 Replies)
Discussion started by: Oddant
3 Replies

8. Shell Programming and Scripting

sed - replacing on the right of a pattern and looking for exact word?

how would you get SED to do the following, say you have the following lines in a text file: user=tigger some text some text some text some text some text some text user=ted some text some text some text some text some text some text user=thekingofrockandroll you want to find any line... (15 Replies)
Discussion started by: rich@ardz
15 Replies

9. UNIX for Dummies Questions & Answers

regular expression for replacing the fist word with a last word in line

I have a File with the below contents File1 I have no prior experience in unix. I have just started to work in unix. My experience in unix is 0. My Total It exp is 3 yrs. I need to replace the first word in each line with the last word for example unix have no prior experience in... (2 Replies)
Discussion started by: kri_swami
2 Replies

10. Shell Programming and Scripting

How to get a next line of a matched word?

Hi , If I match a word in a file, I want to pick the next line of that matched word. My file is a below format- The ntrag trace has auditError Line5005 contains transaction Ntrag data ------------ Here I wanted if I match a word auditError, I need to get the next line "Line5005... (10 Replies)
Discussion started by: Muktesh
10 Replies
Login or Register to Ask a Question