I think I've sort of cracked it. I've understood the gist of unilover's solution, and I've managed to incorporate part of his approach into my initial attempted solution. Now I've got a working solution that's based on what I tried initially and on unilover's solution. And look mom, no error messages!
Here it is:
So first grep lists all the lines in /tmp/tmp.mail that contain "begin", and it prefixes the lines it prints with their respecive line numbers in /tmp/tmp.mail (that's what -n does).
Then awk throws away everything except the line numbers.
Then sed replaces each line number with "tail -n +\1 /tmp/tmp.mail | uudecode", where "\1" is substituted with the respective line numbers. Because this string contains slashes ("/"), we're not using the / as a separation character in the subsititute command, we're using an arbitrary other character instead (":" in our case). We could also escape them like so
, but we're too lazy for that.
Then each of the "tail -n +\1 /tmp/tmp.mail | uudecode" strings are passed to sh, so they can be executed instead of being just standard output.
The tail and uuencode commands work as I described in my earlier post.
I guess that leaves me to try and crack Franklin52's solution next.
I want to run tail -f to continuously monitor a log file, outputing a specific field to a second log file. I can get the first portion to work with the following command:
tail -f log | awk '{if ($1 == "Rough") print $5}'
also:
awk '{if ($1 == "Rough") print $5}' <(tail -f log)
The... (2 Replies)
Hi
I have a file with lots of line feeds and form feeds (page break). Need to replace last occurrence of form feed (created by - echo "\f" ) in the file with line feed.
Please advise how can i achieve this.
TIA
Prvn (5 Replies)
Hello,
I am using a tail command to fetch the line before last in a log file.
the two last lines are as followed:
11-01-16 11:55:45.174 | CClientObject::InitTraceLevelInCache Starting
CClientObject::InitTraceLevelInCache End
I am doing a awk statement to gather only the numeric... (1 Reply)
I need some advice, I have live feed containing xml messages which means there is new messages every minute. I need a script that will run every 2 hours using the current time minus 2 hours ( which I able to do) However I have problem with the date formatting i.e.
One date is... (3 Replies)
Hello all,
I have data like
"1"|"My_name"|"My_Email"|"My_Last"|My_other"
"2"|"My_name"|"My_Email"|"My_Last"|My_other"
"3"|"My_name"|"My_Email"|"
"|My_other"
"1"|"My_name"|"My_Email"|"My_Last"|My_other"
Need output like
"1"|"My_name"|"My_Email"|"My_Last"|My_other"... (10 Replies)
Hi Forum.
I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type.
The main command in the script is:
awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Hello,
Can someone please share a Simple AWK command to append Carriage Return & Line Feed to the end of the file, If the Carriage Return & Line Feed does not exist !
Thanks (16 Replies)
Hello,
I would like to write script to tail a file for different environment
But the number of lines are keep changing
How can I write a script
For example:
env could : A, B or C
and log files could be a.log, b.log and c.log
with the number of lines can change
say sometimes it 100 last... (9 Replies)