You are not logged in.
Say I have a file that looks like this
*background:
rgb:FF/FF/FF
*color0:
rgb:0/0/0
*color8:
rgb:68/68/68
*color1:
rgb:B2/18/18
*color9:
rgb:FF/54/54
*color2:
rgb:18/B2/18
*color10:
rgb:54/FF/54
*color3:
rgb:B2/68/18
*color11:
rgb:FF/FF/54
*color4:
rgb:18/18/B2
*color12:
rgb:54/54/FF
*color5:
rgb:B2/18/B2
*color13:
rgb:FF/54/FF
*color6:
rgb:18/B2/B2
*color14:
rgb:54/FF/FF
*color7:
rgb:B2/B2/B2
*color15:
rgb:FF/FF/FF
*foreground:
rgb:0/0/0
I want to put all the lines that start with rgb at the end of the line before them. Sounds simple, right? I can do this if I open up ex manually and type in three commands, but I want to be able to just type one command into the terminal/use this in a script. I looked at the man page and thought -c would solve all my problems, but I can't get it to work. I'm trying
ex -c "g/\*/j
w
q" file
The only ways I can get it to work is are practically the same thing, run ex in script mode and give it a script file/pipe the commands into it
ex -s file < ex_script
# or
echo "g/\*/j
w
q" | ex -s file
What am I doing wrong? Also, how can I put multiple ex commands on one line? Is that possible?
I know how to do this with sed also, but I'd rather do it with ex because I think it'll be less obtuse.
Last edited by jac (2010-07-06 10:59:44)
Offline
I have never masted their use (so I cannot provide any examples) but I believe this is exactly what sed, and maybe awk are for.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
As I said, I can do it with sed, but sed is not designed to work with multiple lines. To do it in sed you need to read the next line, and then change the \n character into nothing, like this:
sed '/\*/ {
N
s/\n//
}' file
Not as pretty as what I'm hoping to get out of ex, plus I just want to know how to use that darn argument, haha. I can only get really simple things to work using -c or +, like 'q', not very useful.
Offline
vim does that by multiple -c arguments. I don't have ex but I guess it's the same
vim -e -c 'g/\*/j' -c wq file.txt
In this case all the -e for ex is good for is stopping it from trying to make the curses window.
Offline
Oh, I was mistaken in thinking vim had its own ex binary/wrapper. I tried the multiple -c commands with ex yesterday, and it only executed the last one. This does work with vim as you have described.
This solves it for me because I thought I was using the ex-thing from vim anyway. Looking at the man page for vim, it has a limit of 10 -c/+ switches, so I'm guessing this is added functionality of vim and that is why it doesn't work with standard ex.
Thank you, Procyon!
Offline