When replacing use tr, if there are conditions to the replace try sed, if the conditions are too complex try awk, and if you need to generate a different format Perl is your freind.
The command simply tests the sed script by echoing the string through it.
So, taking a look at the sed substitution command: sed invoke the stream editor, sed. 's/ prevent the shell interpreting anything with the single quote and invoke a substitution of everything between the first / slashes with what's between the second / slashes. \. a literal dot character (un-escaped . matches any character) \( begin a capture group, everything between the escaped parenthesis is stored as \1 (subsequent parenthesised groups would be saved as \2 etc...) [a-zA-Z] any letter between a and z or A and Z (ie a letter of any case), the [ ] is known as a range and the expression will match any character in this range \+= match the previous token (the range) more than once followed by a literal "=" \)/ End capture group and end expression to be substituted and begin expression to replace it with. ,\1 a comma and the group we captured in the LHS of the substitution. /g end of substitution expression and global modifier so that this is done throughout the string.
The Linux documentation project has a sed primer available
Hi All,
I have a requirement to replace consecutive occurence of same string nedd to be replaced. Below is the input and desired output.
Input:
---------
123.5|ABC|.|.|.
234.4|DEF|.|.|.|.|.|
Output:
---------
123.5|ABC|||.
234.4|DEF|||||
so basically "|.|" need to be replaced with... (9 Replies)
Hi,
Need help on replacing every second instance of delimeter.
Scenario:
var="Name1,Value1,Name2,Value2,Name3,Value3,Name4,Value"
I want every second "," to replace with "|"
I tried like below
echo $var| sed 's/,/|/2'
But, it's not working.
Expected output:
... (4 Replies)
Hi Unix Mates,
I have requirement where in which I have to replace second to last -1 occurence of space with a word and last occurence of a space with a word and a space,input would be a file.
Desired result:
Second consecutive to last-1 occurence of space replace with: HRU
LAST... (5 Replies)
Hello.
Using a bash script , I have a variable name for the file I want to modify
FILE_TO_EDIT="/etc/my_config_file"And I have a variable name for the parameter to change
PARAMETER="fallback_node"
PARAMETER_NEW_VALUE="http://my_server_name.com/new_path"
A config file may contain :
1°)... (2 Replies)
HI
I'm terribly new to perl .. I;ve been trying to use this command to search and replace entries in a file
I tried this and it works
perl -p -i -e 's/old/new/' filename
Problem is that I have a list of email addresses and I need to serach and replace the entire email address as my... (5 Replies)
I have a record like the one given below.
010000306551~IN ~N~ |WINDWARD PK|Alpharetta|
If ~ is present more than instance in a line,then I need to delete those instances.
Any ideas?
I am working in Solaris (7 Replies)
Hi all,
I have file with following content
...........................
..........TEST..........
..........TEST..........
.....................
.....TEST..........
.....................
.....................
.....TEST..........
I want to replace nth "TEST" with "OK" using... (4 Replies)
Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem.
I need... (1 Reply)
Can someone help me with this command?
I want to replace amount fields which are in the format $99.99 to 99.99 in a large data file which is within a HP box.
I use Vi editor and tried this command
:1,$s//$///g
And this does not seem to work
Also, I want to replace ^M with spaces in the... (1 Reply)