How to replace some specific words from file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace some specific words from file?
# 1  
Old 12-29-2016
How to replace some specific words from file?

I have the file like this.

Code:
cat 123.txt
<p> <table border='1' width='90%' align='center' summary='Script output'> <tr><td>text </td> </tr> </table> </p>

I want to replace some tags and want the output like below. I tried with awk & sed commands. But no luck. Could someone help me on this?

Code:
cat 123.txt
<tr><td>text </td> </tr>



Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags. Thank you.

Last edited by bakunin; 12-29-2016 at 11:32 AM..
# 2  
Old 12-29-2016
Quote:
Originally Posted by thomasraj87
I tried with awk & sed commands. But no luck.
To find out what was wrong with your sed- and awk-commands it would greatly help to post them. As a matter of fact my crystal ball is in repair right now, so you will have to post your code.

bakunin
# 3  
Old 12-29-2016
replace = remove? And, by what criteria?
# 4  
Old 12-30-2016
based on your given input and output.

Code:
bash-4.1$ grep -o "<tr.*/tr>" a.txt
<tr><td>text </td> </tr>

bash-4.1$ sed "s#.*<tr#<tr#;s#/tr>.*#/tr>#" a.txt
<tr><td>text </td> </tr>

# 5  
Old 12-30-2016
From what you have told us, this will achieve your output, but I would bet my house it isn't what you really want:-
Code:
echo "<tr><td>text </td> </tr>" > 123.txt

You need to tell us how/why a transformation is performed and what attempts your have made so far so we can try to understand your needs properly. Output/errors are very useful in diagnosing where it's not doing quite what you want, but you would need to show some meaningful input & desired output before we can be sure we are going in the right direction.



Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. UNIX for Advanced & Expert Users

List all file names that contain two specific words. ( follow up )

Being new to the forum, I tried finding a solution to find files containing 2 words not necessarily on the same line. This thread "List all file names that contain two specific words." answered it in part, but I was looking for a more concise solution. Here's a one-line suggestion... (8 Replies)
Discussion started by: Symbo53
8 Replies

3. Shell Programming and Scripting

How to replace words in file?

Hi Guys, I have a text where we used Ram in 10 times now I want replace all Ram words by Shyam word then how to do it. (6 Replies)
Discussion started by: aaditya321
6 Replies

4. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

5. Shell Programming and Scripting

Replace specific words with nothing

Hi I have a file like that contains infomation about genes exons introns made as a single string. i am just planning to get the gene name alone with out any extra information. intergenic_Nedd4_exon_0_F Gapvd1_intron_24_R Gapvd1_exon_25_Rmy output file should be intergenic_Nedd4 Gapvd1... (13 Replies)
Discussion started by: raj_k
13 Replies

6. Shell Programming and Scripting

Search a test file for specific words

I have the need to search a text file from my unix script to determine if it contains the strings of: 'ERROR' and/or 'WARNING'. By using Grep I can search the file and return a where one of these strings exists. Like this: cat myfile.txt | grep ERROR Output: PROCESS ERROR HERE ... (3 Replies)
Discussion started by: buechler66
3 Replies

7. Shell Programming and Scripting

List all file names that contain two specific words.

Hi, all: I would like to search all files under "./" and its subfolders recursively to find out those files contain both word "A" and word "B", and list the filenames finally. How to realize that? Cheers JIA (18 Replies)
Discussion started by: jiapei100
18 Replies

8. UNIX and Linux Applications

Reading a file for specific words

Hi I have a script where the user calls it with arguments like so: ./import.sh -s DNSNAME -d DBNAME I want to check that the database entered is valid by going through a passwd.ds file and checking if the database exists there. If it doesn't, the I need to send a message to my log... (4 Replies)
Discussion started by: ladyAnne
4 Replies

9. Shell Programming and Scripting

To fetch specific words from a file

Hi All, I have a file like this,(This is a sql output file) cat query_file 200000029 12345 10001 0.2 0 I want to fetch the values 200000029,10001,0.2 .I tried using the below code but i could get... (2 Replies)
Discussion started by: girish.raos
2 Replies

10. UNIX for Dummies Questions & Answers

Search File for Specific Words

I have a file that contains the following: Mon Dec 3 15:52:57 PST 2o007: FAILED TO PROCESSED FILE 200712030790881200.TXT - exit code=107 Tue Dec 4 09:08:57 PST 2007: FAILED TO PROCESSED FILE 200712030790879200a.TXT - exit code=107 This file also has a lot more stuff since it is a log file.... (2 Replies)
Discussion started by: mevasquez
2 Replies
Login or Register to Ask a Question