Stream editor hell!
Phew, it took me longer to try to write a sed command, than to do what I wanted by hand.
Let me save you the introduction and go io the real deal. I want do do this: All files in the directory, remove the unnecessary extensions and output the results to a file? No problem! test2.cfg test1.cfg $ ls | sed 's/.cfg//g' > output (Note, there are about 300~ files for this command, I just added two now) Eh, now we are getting to the real deal. I want to do this: function "(copy the last word of the line here)" excec test2.cfg so, the result would be fairly simple function "test2.cfg" exec test2.cfg function "test1.cfg" exec test1.cfg Now, since I am a newbie, I had no idea how to accomplish it. So, I thought to do this: $ sed 's/^/function " " exec /g' output > output2 And then! $ sed "s/" "/$(cut output)/g" output2 > output3 But it won't work because the file goes multiple lines, not test2.cfg test1.cfg. If the file "output" had only one line "test2.cfg", the command would work, but I would get: function "test2.cfg" exec test2.cfg function "test2.cfg" exec test1.cfg function "test2.cfg" exec test3.cfg function "test2.cfg" exec test6.cfg function "test2.cfg" exec test2.cfg function "test2.cfg" exec test5.cfg function "test2.cfg" exec test2.cfg Just a quick note, file names do not contain numbers They are more something like this hikns.cfg behia.cfg iaeiipuh.cfg etc! Anyone care to help me? Thank you VERY much, I have been playing with this all day. |
What about this?
Code:
sed 's/\(.*\)/function "\1" exec \1/' output |
Quote:
Code:
ls | sed 's/.map//g' | sed 's/\(.*\)/function "\1" exec \1/' > output |
Two seds not required you just need to combine them:
Code:
ls -1 | sed -r 's/(.*)\.map/function "\1" exec \1/' > output -r is there to stop the need for escaping the brackets. |
Beautiful, thank you :)
|
All times are GMT -5. The time now is 04:06 PM. |