Append file with grep output but add timestamp?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Append file with grep output but add timestamp?
# 8  
Old 06-25-2009
Quote:
Originally Posted by Sepia
No joy, still missing text.
Thanks.
could you show the input to 'sed' that it's munging wrongly, please?
# 9  
Old 06-25-2009
Quote:
Originally Posted by vgersh99
could you show the input to 'sed' that it's munging wrongly, please?
Yes, it is 'User Session: Current user count: 300' and is coming out as ',Thu Jun 25 12:56:00 BST 2009count: 300'

Also, how can I add another input like date.

I've tried doing sed "s/^/`date`, /`hostname`, /" but it didn't work.

Thanks.
# 10  
Old 06-25-2009
Quote:
Originally Posted by Sepia
Yes, it is 'User Session: Current user count: 300' and is coming out as ',Thu Jun 25 12:56:00 BST 2009count: 300'
Code:
$ echo 'User Session: Current user count: 300' | sed "s/\$/,`date`/"
User Session: Current user count: 300,Thu Jun 25 15:59:57 CEST 2009

works just fine
Quote:
Originally Posted by Sepia
Also, how can I add another input like date.

I've tried doing sed "s/^/`date`, /`hostname`, /" but it didn't work.

Thanks.
Code:
$ echo 'User Session: Current user count: 300' | sed "s/^/`date`,`hostname`,/"
Thu Jun 25 16:03:59 CEST 2009,bbpser170,User Session: Current user count: 300

# 11  
Old 06-25-2009
Quote:
Originally Posted by vgersh99
Code:
$ echo 'User Session: Current user count: 300' | sed "s/\$/,`date`/"
User Session: Current user count: 300,Thu Jun 25 15:59:57 CEST 2009

works just fine
It works fine for me on an echo but not with the grep.

Quote:
Originally Posted by vgersh99
Code:
$ echo 'User Session: Current user count: 300' | sed "s/^/`date`,`hostname`,/"
Thu Jun 25 16:03:59 CEST 2009,bbpser170,User Session: Current user count: 300

That works fine with echo and grep! Thank you.

Any ideas how I can >> the output to a file on another server?

Have tried >> username@server.com:/var/tmp/cron-log to no avail.
# 12  
Old 06-25-2009
Quote:
Originally Posted by Sepia
It works fine for me on an echo but not with the grep.



That works fine with echo and grep! Thank you.

Any ideas how I can >> the output to a file on another server?

Have tried >> username@server.com:/var/tmp/cron-log to no avail.
cannot do that unless the 'other server' directory is NFS mounted.
# 13  
Old 06-25-2009
Quote:
Originally Posted by vgersh99
cannot do that unless the 'other server' directory is NFS mounted.
Thats a shame.

Thanks for your help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Append to a file repeating output

Hello, i'm trying to force a command to read every second from an interface watch -n1 (command) /dev/x | cat >> output but it continue to overwrite the file, without append the content Thanks and advace for help as usual regards (4 Replies)
Discussion started by: Board27
4 Replies

3. Shell Programming and Scripting

Append timestamp create .trg file for all content of an unzipped archive

Hi, I have a test.zip archive that contains test.zip --> (file_1.txt, file_2.txt , file_3.txt) I need to unzip the file like this, file_1_timestamp.txt file_1_timestamp.trg file_2_timestamp.txt file_2_timestamp.trg file_3_timestamp.txt file_3_timestamp.trg Could you please let me know... (7 Replies)
Discussion started by: Shandel
7 Replies

4. Shell Programming and Scripting

How to append timestamp in the filenames using find?

Hi, How to change the filenames with timestamp in sub folders I have the following code to select the records. find . -type f -name '*pqr*' -ctime 1 -print The following is the example app_root_dir="/`echo $ScriptDir | cut -d'/' -f2`" $app_root_dir/../BadFiles directory uvw.bad... (3 Replies)
Discussion started by: bobbygsk
3 Replies

5. Shell Programming and Scripting

append an output file with two columns

Hi All, can you help me with this: grep XXX dir/*.txt|wc -l > newfile.txt - this put the results in the newfile.txt, but I want to add another column in the newfile.txt, string 'YYYYY', separated somehow, which corresponds on the grep results? For example grep will grep XXX dir/*.txt|wc -l >... (5 Replies)
Discussion started by: apenkov
5 Replies

6. UNIX for Dummies Questions & Answers

Output to file but append rather than overwrite?

I am running a command which has a parameter that outputs the results to a file each time it is run. Here is the command: --fullresult=true > importlog.xml Can I add the output to the file rather than creating a new one which overwrites the existing one? If not can I make the file name... (2 Replies)
Discussion started by: Sepia
2 Replies

7. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

8. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

9. Shell Programming and Scripting

Append Output to another file in Perl

Hi All, I am writing a Perl script such that the output from "perl myscript.pl file1" to be appended to another file name called file2. I tried out with the below code but couldn't work. Can any expert give me some advice? open(OUTPUT, 'perl myscript.pl file1 |'); close OUTPUT;... (7 Replies)
Discussion started by: Raynon
7 Replies

10. Shell Programming and Scripting

Append output to file

Hi, I have a script below. It get's the data from the output of a script that is running hourly. My problem is every time my script runs, it deletes the previous data and put the current data. Please see output below. What I would like to do is to have the hourly output to be appended on the... (3 Replies)
Discussion started by: ayhanne
3 Replies
Login or Register to Ask a Question