General :: Sed Scripting "replace Value For Only Last Part Of A Pattern "?
Apr 26, 2010
All i want is to replace some part of pattern.eg:$1=" alok 10"i want to change 10 with any number/string so that result comes as "alok 20". Is itpossible with sed ?I am looking for code some thing related as :echo "alok 10" |sed -ie "s/$1/$1 10/g I know the above is wrong , its just for your reference. Also, while replying kindly explain wherever is required.
View 3 Replies
ADVERTISEMENT
Feb 24, 2010
I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?
View 1 Replies
View Related
Apr 18, 2011
Just using shell scripting, how can I insert text into the middle of a file name. The file has a predictable pattern, let's say 3 letters and 3 numbers and I want to insert text in the middle of those 2 patterns. Say ABC123 is the file name. As a result, the file name should be ABC.blah.123
View 2 Replies
View Related
Jun 11, 2010
I want to replace a pattern in a file.The file format is given below.
111111
path=/home/fun/
222222
path=/home/fun/
[Code]....
I want to replace "path=/home/fun" with another pattern, but only under "111111", all the others should be the same.
View 14 Replies
View Related
Nov 22, 2010
I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
I want to replace it by something like:
Code:
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
I tried:
1.
Code:
result:
Code:
2.
Code:
result:
File remains unchanged
3.
Code:
result:
Code:
4.
Code:
result:
Displays the unchanged testfile
How I can automate the pattern replacement?
Code:
View 9 Replies
View Related
Jan 20, 2010
got a textfile with : as delimiters in between fields. e.g.1:2:3:4:5:6Thomas Cruise:Johnavid:Peter:Betty:JaneThe names may or may not contain white spaces.I am required to substitute any one of these names in the file with a new one inputted by user.e.g. to change John to Johnny, David to Beckham, etc. without touching any of the other names in the same line. Just one at a time.So here's the sed expression I was trying out with:
sed -i "s/<(.:.:)David>/$1Beckham/" names.txt
I also tried:
sed -i "s/<(.*)David>/<1Beckham>/" names.txt
[code]....
View 24 Replies
View Related
Apr 12, 2010
I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things
1) create a copy of existing file.
2) add a new line to the copied file.
3) strip off all the absolute paths inside the copied file
The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,
PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG
The output of the script should look like,
PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG
View 14 Replies
View Related
Dec 15, 2009
Here's the actual line of code, which exists in a bash script:
Code:
I want to replace instances like this:
Code:
with this:
Code:
Using this:
Code:
Which works great when there's only ONE of the pattern on the line. But in a case like the "actual line" I posted first, where there are two patterns, separated by a slash, only ONE gets replaced
Watch:
Code:
Why? There must be (among many other things) something I'm not knowing about sed, that's causing this.
-- I'm currently using the ~ (tilde) as the separator in the sed command. It doesn't matter, I've used / ~ and % with no difference.
-- As a test, I tried putting a different character(s) in the middle of the original pattern instead of the / but that made no difference.
-- I've come up with various similar but slightly different regexs that will do this replacement, but they all have had this same result.
-- I tried the sed single-quoted, double-quoted, and unquoted; the latter fails to execute, and the formers both work as described here: wrong.
View 7 Replies
View Related
Apr 24, 2010
Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.
[code]....
My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:
[code]....
Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.
[code]....
how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?
View 10 Replies
View Related
Jun 11, 2009
I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?
View 2 Replies
View Related
Jan 8, 2010
There are a few things I was wondering about (using tools available in bash):How to insert a file at at the specified location of another.How to copy a portion of a file between two lines matching a regex to another file (and/or making sed only work between two lines matching a regex)How would you do this?
View 2 Replies
View Related
Aug 30, 2009
I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:
<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">
I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">
All I need to do is duplicate the line but replace "normal" with "thumbnail"
Each file can have multiple img src tags with different numbered jpgs.
I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
View 2 Replies
View Related
Oct 11, 2010
I want to go through a log file and find pattern1 and then a pattern2 only after pattern 1.So for example I want to know howManyRecords was in 13:30.I figured I grep for "start time for the job" and then only after that (and before the next occurence of that) grep for "howManyRecords". Is this a sane way?
View 1 Replies
View Related
Apr 29, 2010
I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
View 3 Replies
View Related
Apr 23, 2011
Can the Replace function replace more than one word with the same character(s)?
Also, do you know how to access the plugins provided by the gedit-plugins package?
View 3 Replies
View Related
Dec 8, 2010
I just used dd to clone a linux partition to a new hard drive, it had 800mb left on the old hard drive, after dd, new hard drive lists 1.29/1.3 terabytes full. Is this what happens by default in dd? How can I fix this?
View 1 Replies
View Related
May 24, 2010
I'm trying to figure out how to access the local part and the domain part of an email address in postfix's main.cf. For example, myname@mydomain.net has myname as the local part and mydomain.net as the domain part.I get the whole email address with %s. I want to speed up the lookups by writing better database queries.I've had no luck finding this in the otherwise well documented postfix.
View 2 Replies
View Related
Jul 13, 2009
we have access to one domain name , 1 internet ip address and may servers hosting different part of site. I want them all to be accessed via same web site . some of the server in our network are embedded devices.they have their specific utility being hosted on that machine. So the severs are bound to be distributed . I just wanted to know how can I access them via single ip, domain name.
View 6 Replies
View Related
Jan 14, 2010
In bootseqence of linux, the first step is check the CMOSRAM(size 64bytes) setup for custmor setting. So i am just confused wether CMOSRAM is a part of motherboard or is a part of RAM itself.
View 4 Replies
View Related
Feb 15, 2011
I want to cut out part of the 'uptime' output so all it displays is the load average. In the end I want to cut out everything before the word 'load'. I am a total sed newbie and could really use some examples or links. I've googled and haven't found anything useful yet.##edit###I used the 'cut' command- The code was Code:uptime |cut -d, -f 2,3,4,5 |cut 13-
View 5 Replies
View Related
Apr 24, 2009
I have the large file (textfile) there are word:
code-007100
...
code-007199
How to substitute those all words, so it will change all instances to:
code-007200
...
code-007299
View 5 Replies
View Related
Sep 17, 2009
Is there a firefox add-on to script HTML and/or Javascript directly inside firefox
View 1 Replies
View Related
Mar 13, 2011
I have a requirement to list files using find command My folder contains below list of files with out extention.I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.
View 7 Replies
View Related
Nov 28, 2010
I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.
View 5 Replies
View Related
Jul 19, 2011
If I wanted to copy all *.so files from src to dst I'd do:
cp src/*.so dst
However, I want to copy all *.so files from src and it's subdirs into dst.
View 2 Replies
View Related
Jul 27, 2011
I would like to remove a string pattern which like this.You should not remove this /*This is the part should remove*/ You should not remove this.I would like to remove all the text inside the /* and */.
View 2 Replies
View Related
Jul 7, 2011
How can I use grep -Ev "pattern" not only to delete the matching "pattern" but to edit and save the file permanently as well
View 2 Replies
View Related
Oct 14, 2010
How do yo find a pattern with sed or awk and then:
- add a # at the beginning of the line containing it
- and add a # at the beginning of the following 2 lines, too?
Say, I want to comment out the line containing "which 0launch" and the two lines following it:
if [ -x "`which 0launch`" ]; then
exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
fi
Expected result:
#if [ -x "`which 0launch`" ]; then
# exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
#fi
I need this because I do not want to comment out every line containing "fi", just the "fi" of this specific if statement.
View 3 Replies
View Related
Mar 5, 2011
Want to grep pattern of root dir. (/). Staying in current directory. But I don't want to use the below code:
cd /
grep m *
View 3 Replies
View Related
Oct 24, 2010
I have some lines of text and I want to detect words that meet some criteria with sed.
E.g. The line "tetris cat dog test cactus stereotype"
I want to detect the word that contains two (2) ore more t letters. That mean the words tetris, test and stereotype.
The following regex doesn't do the job because it can;t distinguish words very well.
I thinks I have ti incorporate something like [^ ] in the regex but I wasn't successful...
View 3 Replies
View Related