Hi guys,i urgently need help in this problem,i need to append one sentence to another line when it meet a certain word.
For example:
root: root time_last_login = 1191232080 root tty_last_login = /dev/vty0 root host_last_login = rep1nim root unsuccessful_login_count = 0 root time_last_unsuccessful_login = 1183617892 root tty_last_unsuccessful_login = /dev/vty0 root host_last_unsuccessful_login = rep1nim
i need to when it meet the word "root",then it will go to the next line..really hope u guys can help..thanks in advance!!
chella
October 23, 2007, 6:47am
2
Hi,
Can you explain more on your problem so that it will be helpful.
Regards,
Chella
Hi,well..what i trying to do is that when the sentence meet the word "root" it will automatically bring the remaining sentences to the next line,it will somehow be like this after what i wanted
root:
root time_last_login = 1191232080
root tty_last_login = /dev/vty0
root host_last_login = rep1nim
root unsuccessful_login_count = 0
root time_last_unsuccessful_login = 1183617892
root tty_last_unsuccessful_login = /dev/vty0
root host_last_unsuccessful_login = rep1nim
Is there anyway to do that with sed or awk???
Can you show a start state then an end state. This would help to define things.
hey hi,well..the starting is what i post in the start of my thread which is like this
starting:
root: root time_last_login = 1191232080 root tty_last_login = /dev/vty0 root host_last_login = rep1nim root unsuccessful_login_count = 0 root time_last_unsuccessful_login = 1183617892 root tty_last_unsuccessful_login = /dev/vty0 root host_last_unsuccessful_login = rep1nim
ending:
root:
root time_last_login = 1191232080
root tty_last_login = /dev/vty0
root host_last_login = rep1nim
root unsuccessful_login_count = 0
root time_last_unsuccessful_login = 1183617892
root tty_last_unsuccessful_login = /dev/vty0
root host_last_unsuccessful_login = rep1nim
ya,thats what i want,hope u guys can help!!thanks!!
you could at least show some effort on your part.
awk 'BEGIN{RS="root"}{print "root " $0}' "file"
hey thanks alot ghostdog!!hmmm..ya..haha..cos i am really damn noob in programming..need some pros help..haha..thanks alot..
hey ya ghostdog,i am just curious,can sed do the same thing?haha..just a question..if cannot i just use awk..thanks
Hi,
Try this one.
nawk '{
gsub(/root/,"\nroot",$0)
print
}' filename
hi thanks for your code!!haha..well..i was wondering if sed could do the same thing,any idea?
chella
October 24, 2007, 6:15am
11
Hi,
Using sed you can do as
sed 's/root/\
root/g' filename
Regards,
Chella