sed append at new line if the old line is not empty
Hi, I want to append at a new line if the old line is non empty.
so it would be something like Code:
1 Code:
1 i figured out the symbol for a new line pattern is ^ so it would probably be sed "a\^stuff here" is this right? but i dont seem to get the right result:banghead: Thanks |
Quote:
Anyway, here is what I think you're looking for: Code:
sed '$ {/^$/ {c newline |
hi, thank you, but i seem to have trouble substituting the variables in:
Code:
sed -i '$ {/^$/ {c newline 1 5 2 5 3 5 45 sorry for my inexperience thanks |
Double quotes are required for parameter expansion. So you need them around the sed command instead of single ones.
|
Any chance someone can help me with a one liner? I won't go over the last sixteen examples that I've tried from the studying I've been doing over the last two hours but I'll just give you the last one.
I have several dozen .txt files in a directory and I wanted to add about four empty lines to the end of each text file before I combine them. I already know how to combine several files with the CAT command. I just need help adding those four lines to the end of each .txt file. Here is 'one' example of what I had tried to do (again I'm sparing you the other sixteen or so examples): Code:
cat * | sed -i '$:/r:g' |
<sigh> ... So I finally ask the question and THEN I seem to have figured it out.
I think this is working for me guys. Let me know if you can think of any improvements or anything that I'm overlooking. Code:
sed -i '$ s/$/ \r\r/' * |
@tg3793
Please start your own thread. Hijacking other people's threads can negatively affect your love life (and is considered rude.) |
Quote:
first of all, please do not hijack other threads. Start your own thread and link to other threads if you think they might help in clarifying the problem. You said you wanted to concatenate the files. I also do not know how your construct will add empty lines. Are you trying to manipulate windows files? Here is one that works with Unix files: Code:
sed -s '$ s/$/\n\n\n\n/' file file2 > combined |
Quote:
http://www.squidoo.com/threadjacking But then again I'm not a Linux veteran and I might have incorrectly assessed that "sed append at new line if the old line" and my issue of "using sed to append a line to the end of a text file" have nothing to do with each other :-) I mean this with complete respect. I don't want to say things on a thread that are unrelated, but on the opposite end of the spectrum I don't want to start a new thread about something that is already being discussed. |
Quote:
However I can see the additional commands that you have above are going to truly make the whole operation a one liner. And for clarification I am on Ubuntu Lucid. I don't know what program the .txt files were made in but it is a book that was broken into separate chapters, which I then want to in turn combine back into a single file (book). Thanks again. I'm sure that this little exchange will be helpful for others in the future. |
The keywords I think where '' start your own". It has nothing to do with the fact you are off topic, It has to do with the fact that everyone who responded is focusing on 1 specific problem (the first posters problem) and introducing a new one will throw people off, Because they'll have to sift through posts to find the one they want to answer, Then you get 5 conversations going at once and it is a mess. So you can start a new thread and keep things more organized and maybe start off with something like:
"Hello, I have a problem much like this: (insert link to this thread) ...blah blah blah" |
Quote:
Hope this helps. |
Quote:
I did a little searching on this forum and I don't seem to be the only one that thinks commenting on an existing thread is beneficial. But I can also see your point as well and I'll be happy to play along with the LQ way of doing things if that's what you guys think is the best for everyone here. |
All times are GMT -5. The time now is 07:18 PM. |