In post #1 in this thread, you showed us two lines of input and said that you wanted to add a word to any line your input file that exactly matched the 1st input line (and maybe then only if the next line contained additional specific text. All of the code suggestions that were made for you assumed that the data you were processing matched the data you said you want to change (explicitly that the text you wanted to change contained the characters !ADS at the end of an input line). So, since you lied about the format of your input data, none of the suggested code matched the input you actually want to change. This is known by the common computer science term GIGO (meaning: garbage in, garbage out).
Now that we know what your data really looks like, I'm sure one of the other people who suggested code before can help you create an RE that can be used to change your data the way you want it to appear. (Although it still isn't clear to me whether you want to add text, or replace existing blanks with the added or replacement text you want to insert.)
It is way past my bedtime, so I'm not going to attempt to figure out what you really want at least until I get some sleep.
I am sorry if i confuse you. My Input contains 13000+ lines of data. As a sample of it i am giving the below.
What i need to do is, I want to replace the string(exact match) Cable Yes && Pay TV && !ADS with the string Cable Yes && Pay TV && !ADS && !MDS.
For ex:- In my above input, Line 4 and Line 8 contains the exact string Cable Yes && Pay TV && !ADS. So i want to replace it with Cable Yes && Pay TV && !ADS && !MDS.
Also, if you observe Line 12 in my Input also contains the string Cable Yes && !Pay TV && !ADS which looks like below:
But i do not want to replace it since its preceding with \noUE \Label="! and ending with "
Likewise in so many other lines the string appears. But my aim is to replace it when it is not preceding/ending with some other words.
Hope I am clear on my specifications now. If not please let me know.
Still not much clear, on an assumption could you please try following and let me know this helps or not.
Most definitely why our codes didn't work previously because you had mentioned like lines which are starting from string Cable and ending from !ADS should be only changed but in your Input_file which you have shown in your previous post doesn't looks same. So I would like to request you please show actual Input_file(Off course not having your confidential information but should have same format near to actual one.) with all the conditions(keep it simple please) and expected sample output.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Thanks for the reply. I will make sure to follow the points you have suggested.
I have tried the code. Only in line 4 , the replacement happen.But the string moved to start of the line. You can see below.
Could you please try following and let me know if this helps you, as can't do much about spaces before the lines, so removing all the spaces from the output as follows, let me know how it goes for you then. EDIT: Adding a non-one liner form for same here.
Thanks,
R. Singh
Last edited by RavinderSingh13; 05-05-2016 at 10:26 AM..
Reason: Added a non-one liner form of solution now.
Hi Ravinder,
Thank you. I have tried it. Now the string replacement done exactly as expected but the space issue is still there.
Is there any chance to overcome it ?
Regards,
am24
Hello am24,
I have fixed that problem in following code, could you please try following and let me know if this helps you.
Output will be as follows.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
I have a file with the contents below "lets say the name of the file is abcxyz" shown at the end of this.
I am using nawk to find the exact ip address and the 6 lines after the match is found using the following nawk statement
/usr/bin/nawk "/111.46.14.107/,printed==6 { ++printed; print; }"... (7 Replies)
Hi guys, I am using Centos 6.3. Actually I posted similar question but I still have some minor problem need be fixed. I have two files,
file1:target: gi|57529786|ref|NM_001006513.1| mfe: -31.4 kcal/mol p-value: 0.006985
target: gi|403048743|ref|NM_001271159.1| mfe: -29.6 kcal/mol p-value:... (11 Replies)
I would like replace all the rows in a file if a row has an exact match to number say 21 in a tab delimited file. I want to delete the row only if it has 21 any of the rows but it should not delecte the row that has 542178 or 563421.
I tried this
sed '/\<21\>/d' ./inputfile > output.txt
... (7 Replies)
I am making a script to relocate a project file. I have all of the variables in place and everything is working except:
the first variable changes everytime it passes thru a loop. The second is a constant value.
when I run that it does what I want...but incorrectly. It is finding... (2 Replies)
Hi friends,
i am using the following grep command for exact word match:
>echo "sachin#tendulkar" | grep -iw "sachin"
output: sachin#tendulkar
as we can see in the above example that its throwinng the exact match(which is not the case as the keyword is sachin and string is... (6 Replies)
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)
I am trying to match a pattern exactly in a shell script. I have tried two methods
awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath
perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath
Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
I'm trying to find a exact word match but couldn't do it.
ABC
ABC_NE
Searching for ABC_NE tried
grep -w </ABC_NE/>
grep "^ABC_NE$"
but didn't worked , any awk variants would also help.
---------- Post updated at 08:40 AM ---------- Previous update was at 06:48 AM ----------
I... (2 Replies)
Hi,
I have sentences like this:
$sent=
Protein modeling studies reveal that the RG-rich region is part of a three to four strand antiparallel beta-sheet, which in other RNA binding protein functions as a platform for nucleic acid interactions.
Heterogeneous nuclear ribonucleoparticle... (19 Replies)