Input File: Output File: So I tried this unsuccessfully in sed: Error: Question:
How do I run the substitute on \2 alone?
I realize that I can use other tools but would like to solve this with sed as more of a theoretical exercise at this point.
Thanks in advance for any help provided.
Peace!
Last edited by Scott; 05-27-2010 at 05:24 PM..
Reason: Code tags, please...
Input File:
somechangeVariable1=Something I would like to change
somechangeVariable2=Something else I would like to change
...
Output File:
somechangeVariable1=Something I would like to different
somechangeVariable2=Something else I would like to different
...
...
How do I run the substitute on \2 alone?
I realize that I can use other tools but would like to solve this with sed as more of a theoretical exercise at this point.
...
Clever but not quite what I wanted;
Here is the rephrased question:
Hi All,
Here is what I'm trying to do with sed:
Input File: Output File: So I tried this unsuccessfully in sed: Error: Question:
How do I run the substitute on \2 alone?
I realize that I can use other tools but would like to solve this with sed as more of a theoretical exercise at this point.
Thanks in advance for any help provided.
Peace!
Moderator's Comments:
Removed some formatting, added code tags
Last edited by Scott; 05-27-2010 at 05:25 PM..
Reason: Code tags, please...
1. h: Copy the original, pristine, unaltered line to the hold space, for future use.
2. s/=.*/=/: From the current line, remove everything that follows the equals sign inclusive, replacing it with just the equals sign. What remains is the variable name (with the trailing equals sign), in which we are not interested in substituting anything.
3. x: Store the variable name in the hold space by swapping the pattern and hold spaces. The original version of the line is now back in the pattern space.
4. s/^[^=]*=//: Remove all leading characters that are not an equals sign and the first equals sign, leaving nothing but the text of interest to the primary substitution operation.
5. s/change/different/g: Substitute each instance of "change" with "different" in the relevant text.
6. H: Append the resulting string to the variable name which we've kept tucked away in the hold space.
7. g: Copy the hold space to the pattern space.
8. s/\n//: Remove the newline that was inserted between the variable name and variable value by step 6's H command.
Last edited by alister; 05-27-2010 at 07:38 PM..
These 2 Users Gave Thanks to alister For This Post:
Let me start off by saying I am a self taught sometimes scripter so what you will see below won't be pretty.
I have created a script to parse through a file with a large amount of data and simply pull out what I need. In doing this I create several files and then paste them together in order to... (2 Replies)
I am trying to do what I thought should be a simple substitution, but I can't get it to work.
File:
Desire output:
I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Hello,
I have huge xml files and I need to replace only part of the data within a particular xml tag. This doesnt seem to be as simple as it sounds. I have searched everywhere and couldnt find any solution.
Ex:
In the below case I would like "def" to be replaced by "xyz" only when found in... (8 Replies)
using awk to substitute data in a column delimited text file
hello i would like to use awk to do the following calculation from the following snippet.
input file
C;2390 ;CV BOUILLOTTE 2L 2FACES NERVUREES ;1.00 ;3552612239004;13417 ;25 ;50 ; 12;50000 ; ; ... (3 Replies)
Is there a way to substitute the URL-encoding references of ( & and ` ) with their actual appearance? for example....
%26 is &
say I want to convert every %26 in my file to &.....
awk '{gsub(/%26/,"&");print}'
Is there a way to do this?
I also want to be able to convert ` too! (3 Replies)
I'm using sed to perform a simply search and replace. The typical data is:
<fig><image href="Graphics/BAV.gif" align="left" placement="break"
I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus:
<fig><image href="NEW_VALUE" align="left"... (3 Replies)
I am trying to get rid of some ending tags but I run into some problems.
Ex.
How are you?</EndTag><Begin>It is fine.</Begin><New> Just about
I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>)
I tried the following
sed... (2 Replies)
Hi All,
I'm currently using SED to make various changes to some .xml files I'm working on, but I'm stuck on this particular problem.
I want to remove '<placeholder>element-name</placeholder>' from the following:
<heading>Element <placeholder>element-name</placeholder> not... (2 Replies)
I am having a problem executing a sed substitute in a file. I have tried alot of different things I found in previous posts, however non seem to work.
I want to substitute this in $FILE:
VALUE=33.4
In the script I have tried the following:
prev=$(awk -F"=" '{ print $2 }' $FILE )
new=$(echo... (16 Replies)