Bash question
Hi,
say you have a file like this: Code:
-- comment 1 Code:
-- comment 1 Thanks advance, A. |
Hi,
Don't know if this is easy or even short (enough), but it works: Code:
#!/usr/bin/perl Hope this helps. |
ok this almost works
Code:
cat comment.txt|sed '/^[[:alpha:]]/N;s/\n/ /' |
Hi again,
Here's a (semi) one-liner: Code:
cat infile | tr "\n" " " | sed -e 's/\(-- comment [1-9][0-9]* \)/\1\ |
It's not pretty and it can probably be made simpler but it's all on one line and it works.
Code:
cat comment.txt|tr '\n' ' '| sed -e 's/--/\n\n--/g' -e "s/\([[:digit:]]\)/\1\n/g" |
ROFL
Almost the same solution within the minute :) drawde83's version using \n in the sed statement could fail on certain platforms, that's why I choose the 'multi-line' one-liner.... If it works on your platform, use that one. |
Thanks for the replies!
drawde, your first script almost works like you said.. :) druuna, I should have also mentioned that comment 1, 2, 3 can be anything and doesn't have to end with a digit. Basically if a string starts with '--' it's a comment. The file actually represents a long sql script where i need to strip off the formatting, ie the new lines. If you have any other ideas please post! |
All times are GMT -5. The time now is 09:43 PM. |