Programming :: Prevent Sed From Replacing With Newline
Nov 28, 2009
I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.
I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.
Is there a way to tell sed to not process escape sequences? I tried using several variations of
Code:
To no avail. Or could it be bash?
I would give up on the script and do it by hand, but this is something that I must do from time to time.
Here's the function which replaces the first occurrence found:
Code:
When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?
I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.
Code: $ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE= The idea is that I'm studying c and want to change the name of the file once instead of
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 can't get x to work with a mouse so I have to use a windows computer to do that from for now. The problem is I remember there being something about windows using a newline AND carriage return and linux just using a newline. I was about to cut and paste code but the lines go on and on instead of breaking off where they did in linux. I was going to write a perl script but don't know how to add a carriage return to the end of each line.
Using xsel I pass a selection into a variable. I then check that the variable includes an embedded newline to be sure that the selection returned by xsel is complete. If the selection content preceding the newline is just a single word, the check fails to detect the newline, thus
I'm having a hard time figuring out why the program posted below prints an extra newline every time I type the enter key.This program is using the master pseudo-terminal to send the password and receive the output from the slave(connected to the passwd program).I suspect this has to do with the terminal line discipline(s)(2 considering the master and slave), but I can't really understand why.I have tried turning on/off several terminal special characters but to no avail.
i am trying to replace the last digit in the ip address(25) with 47 using following:Quote:echo 192.168.0.25|sed -r s/([0-9]*.[0-9]*.[0-9]*)/47/g'but not able so far, was wondering if you can help, so i can find my mistake.
I would like to replace 'xxxx' with 'yyyy' which is in a file xyz.csproj not sure of what 'xxxx' is, it can be 3055, 4056, 7089 etc. I know it always appears at line # 5 and at character 50.
working on a script to update .Jar file, I have tried jar xf to unpack and jar cf to repack it is giving me java.lang.NoClassDefFoundError exception at main class. I also tried jar uf, which is also not working for me Basically my jar file requires to update date, which i do from "winrar" Manual it works fine, but now to remove "Donkey work", i want to make an script which does this all automatically, and the last stage is to update jar file which is not happening.
I have always encountered this problem in ubuntu bash shell scripts that echo command in a function will be treated as a return value when used in a function. e.g.
[code]...
The output would simply be xyz. Hence the echo seems to function as a "return" command when used in a function with a return value.
I want to know, is there any way to prevent the multi-thread process from crashing if some errors (say, segmentation faults) occur in one of its child threads? I've found pthread_sigmask() function, but that does not seem to work:
If I would like to replace "one" with "six" I would do this:
cat temp.txt | sed 's/one/six/' word/six/two/three
Now I want to replace "one/two" with "six/seven" and these options don't work: cat temp.txt | sed 's/one/two/six/seven/' (OFCOURSE) cat temp.txt | sed 's/"one/two"/"six/seven"/'
I even want to be able to replace "one/two" with "six/seven/eight"
I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment.
At line 7843 of both files there is a cartesian coordinate X, Y and Z ( three digits ). And at line 15685 there is another three digits. The number of lines in between two cartesian coordinates are 7841. And there are few hundreds of thousands of lines in a file.
What I need to do is copy the X Y Z coordinate (three digits) from file1.traj at line 7843 and paste into file2.traj at the same line number as in file1.traj. The next line will be 15685 from file1.traj and replace at line 15685 at file2.traj. And I dont want other lines (data) in file2.traj get altered. This sequence shall be going on until the end of the file. Means copy and substitude the selected lines from file1.traj into file2.traj.
I tried to use paste command but I cant do for specified line alone.
Here i showed the data format in the file. I used the line number for clarity purpose.
I am working with bash scripting and running into a weird issue where the trailing newline characters are being truncated.The file contents are something like:
Code: # Catting the file shows the trailing characters cat /tmp/junk first line second line
[Code]...
Since I am working with config files, some of the applications/daemons fail to start if they fail to find trailing newline characters
I've noticed when I create a generic textfile in vim and have a trailing newline at the end of the file, when I open it with kate it has 2 new lines at the end of the file instead! This is on a fedora machine. The same behavior is observed when I copy the file over to my windows machine and open it in notepad++ (which is able to handle both unix and dos newlines) - 2 newlines instead of 1.
Feeling curious, I tried creating a textfile in vim on my ubuntu machine and used gedit to open it, but surprisingly gedit displayed it correctly - only 1 newline.
I've been playing around with sed but can't find a way to remove the <br> html tag and replace it with a newline. Sed isn't truly needed awk or other suggestions could be good.
Concatenating two files without creating a newline between them? So how is it possible to do that? I've tried the following: Code: echo 123 > file1 echo 456 > file2 cat file2 file2 > file3
I have bash script which has lots of echo statements and also I aliased echo to echo -e both in .bash_profile and .bashrc, so that new lines are printed properly for a statement like echo 'Hello World' the output should be I even tried using shopt -s expand_aliases in the script, I am running my script as bash /scripts/scriptnm.sh; if I run it as . /scripts/scriptnm.sh I am getting the desired output.
Currently i'm doing a script for my project and I want to prevent people from exiting the terminal by clicking the "X" at the top right. when I run the script, user cannot exit out of the terminal unless the scipt finish running.