Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Search for a string,delete the line and replace with new string in a file Post 302956249 by RavinderSingh13 on Monday 28th of September 2015 11:04:01 AM
Old 09-28-2015
Quote:
Originally Posted by Pradhikshan
Thanks for your reply but i would like to delete the line that has the matching string and then replace the line with new string.
Hello Pradhikshan,

Following may help you in same, here I have taken an example of *.txt files, you can make it as per your requirement.
Code:
for i in *.txt; 
do 
   sed -i 's/^test test test$/"My new line here R. Singh"/g' $i; 
done

Line sed -i 's/^test test test$/"My new line here R. Singh"/g' $i; can be explained as sed -i 's/^Your required line to be changed$/"Your new line"/g' $i; Hope this helps you, let us know if you have any queries on same.

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-28-2015 at 12:05 PM.. Reason: Added a comment about command explaination
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

2. Shell Programming and Scripting

search string and delete the line

Hi All, I have a file from Mainframe which has one of the lines with so many words... i tried to fold, format to 80 chararcter.. stil did not work. So i have decided to search for a string in that line Ex.FLIGHT PLAN and once if it is found i want to delete the entire line. Please help... (2 Replies)
Discussion started by: digitalrg
2 Replies

3. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

4. UNIX for Dummies Questions & Answers

Search a string in the file and then replace another string after that position

Hi I am looking for a particular string in a file.If the string exists, then I want to replace another string with some other text.Once replaced, search for the same text after that character position in the file. :wall: E.g: Actual File content: Hello Name: Nitin Raj Welcome to Unix... (4 Replies)
Discussion started by: dashing201
4 Replies

5. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

8. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

9. UNIX for Beginners Questions & Answers

Need help with how to search a file for a variable string and delete that line

Hi, I have a working script. It does what I am intending it to but a bit confused whether the sed part is supposed to be working or not. Further down is the script with the sed part that should have been working but not and the grep -v part which is the workaround that I am using at the... (10 Replies)
Discussion started by: newbie_01
10 Replies

10. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies
gendesc(1)							   User Manuals 							gendesc(1)

NAME
gendesc - Generate a test case description file SYNOPSIS
gendesc [-h|--help] [-v|--version] [-o|--output-filename filename] inputfile DESCRIPTION
Convert plain text test case descriptions into a format as understood by genhtml. inputfile needs to observe the following format: For each test case: - one line containing the test case name beginning at the start of the line - one or more lines containing the test case description indented with at least one whitespace character (tab or space) Example input file: test01 An example test case description. Description continued test42 Supposedly the answer to most of your questions Note: valid test names can consist of letters, decimal digits and the underscore character ('_'). OPTIONS
-h --help Print a short help text, then exit. -v --version Print version number, then exit. -o filename --output-filename filename Write description data to filename. By default, output is written to STDOUT. AUTHOR
Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com> SEE ALSO
lcov(1), genhtml(1), geninfo(1), genpng(1), gcov(1) 2010-08-06 LCOV 1.9 gendesc(1)
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy