Can someone kindly help with appending problem!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can someone kindly help with appending problem!!!
# 1  
Old 10-23-2007
Can someone kindly help with appending problem!!!

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!!
# 2  
Old 10-23-2007
Hi,

Can you explain more on your problem so that it will be helpful.

Regards,
Chella
# 3  
Old 10-23-2007
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???
# 4  
Old 10-23-2007
Can you show a start state then an end state. This would help to define things.
# 5  
Old 10-23-2007
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!!
# 6  
Old 10-23-2007
you could at least show some effort on your part.
Code:
awk 'BEGIN{RS="root"}{print "root " $0}' "file"

# 7  
Old 10-23-2007
hey thanks alot ghostdog!!hmmm..ya..haha..cos i am really damn noob in programming..need some pros help..haha..thanks alot..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending 2 text files - Problem in windows

Hello, I have text files to append and am able to do with cat. cat file1 file2 >file3 and file3 works fine in UNIX (checked with vi and it looks fine) but when i open the same file in windows I see 2nd file appended as a single-line. In other words, all the lines of 2nd file appended to... (2 Replies)
Discussion started by: magnus29
2 Replies

2. Shell Programming and Scripting

Problem in appending text to a file located in remote server

ssh -q "server_name sudo echo 'dbagroup::1234' >> sudo /etc/group"if i execute the above code its not getting appended. my requirement is to login to remote server and append dbagroup::1234 in /etc/group i am able to achieve this with tee -a command want to know why its not working with >>... (5 Replies)
Discussion started by: chidori
5 Replies

3. Shell Programming and Scripting

sed appending problem

i have a number of java files containing eg: --------------myfile.java-------------- package zip.fun.myfiles; import java.* import something..; import sdfdfdsa; ... ... -------------------------------------------- Now I need to append / insert a line as follows: ... (10 Replies)
Discussion started by: linuxadmin
10 Replies

4. UNIX for Dummies Questions & Answers

Appending timestamp problem

Hi, I am trying to insert a timestamp after all the file names in a folder,after the timestamp is created in the filename the file size is becoming zero bytes. please tell me where I am doing it wrong. I have declared the variable in starting of my script. timestamp=`date... (1 Reply)
Discussion started by: shruthidwh
1 Replies

5. Solaris

CJS instalation one problem...kindly help

hi am installing CJS frm one server to a cleint and i first did ./add_install_client -e now i need to know the mac add of the client so i entered into client and now hopw can i go to ok prmt ^] when this symbol is entered am nt being able to enter to ok promt what to do i... (1 Reply)
Discussion started by: all_is_well
1 Replies

6. Shell Programming and Scripting

Problem with appending a file!

Hi All, I have a script which i use in office. This script is used to log the work in users name. For that in the script itself I have added that the infomration should append to the logfile everytime the script is run. LOGFILE=/data/log/request1.txt All these days it was... (3 Replies)
Discussion started by: smarty86
3 Replies

7. Solaris

Problem in appending the correct log

Hi All, I have a perl module TrxLog.pm and following are codes in it #!/usr/local/bin/perl package TrxLog; %log_begin=""; %log_end=""; %log_msg=""; %log_start_time=""; %log_end_time=""; $ix=0; @arr_msg=""; if (! -e "TrxLog.txt"){ open (TRX,">TrxLog.txt"); }else{ ... (1 Reply)
Discussion started by: megh
1 Replies

8. Shell Programming and Scripting

kindly help me out on this please

Hello experts, please help me on this. This is the scenario: I have applications like BigBrother,PowerKeeper/PowerBroker etc.. which I have to install during server build for both AIX and Solaris. I already have separate installation scripts for both OS for all applications. Now, I want to... (0 Replies)
Discussion started by: solaix14
0 Replies

9. Shell Programming and Scripting

FOR loop problem: Kindly Help

Hello Friends, I have file called reference.txt which looks like below, columns are been formed by delimiter "|" as shown. I am required to scan whole file line by line & compare 1st 2 columns with new name (ex. ferrari) & new version (2.1). CODE PURPOSE: whnever new project formed... (6 Replies)
Discussion started by: okdev
6 Replies

10. Shell Programming and Scripting

AWK scripting problem - appending values

ABC:10:A1:ABCA110 ABC:10:A1:ABCA110 ABC:20:A1:ABCA120 DEF:20:D1:DEFD120 GHI:30:G1:GHIG130 GHI:40:G1:GHIG140 JKL:30:J1:JKLJ130 MNO:10:M1:MNOM110 What I'm trying to do is look through a file that consists of four columns (as above). As you can see there are duplicates in the file, i.e.... (2 Replies)
Discussion started by: rowntree
2 Replies
Login or Register to Ask a Question