Ok, I've now looked at Franklin52's proposed solution. While I don't know awk that well and haven't understood it completely, I know that it doesn't really apply to my issue at all, and does something completely different.
Here's what Franklin52 wrote:
That means /tmp/tmp.mail is used as input for the
awk script.
The script looks for the "begin 666" pattern and then extracts the file name written after that (i.e. $3 = the third item on that line, after "begin" and "666"). This file name is stored in a variable called name. The script then pipes the contents of /tmp/tmp.mail from after the current "begin 666" line up to the next line containing "begin 666" into a file that is called whatever the name variable says. Apparently this process is then repeated.
The result is that the current directory contains a bunch of files that are correctly named (IMG_something.jpg in my case), but they are not jpeg files, because they have not been uudecoded. They just each contain the uuencoded data for a single JPEG file without the begin line (but with the end line still included).
It's not even possible to then manually uudecode these files, because uudecode expect proper begin and end lines (because otherwise it wouldn't know what to name its output file and what permissions to give it, and where the uuencoded data ends):
Even if the begin line were still included, it wouldn't work this way, because the (input) file with the uuencoded data would have the same filename as the (output) file uudecode would try to create. Out of curiosity, I tried this by using vi to edit the "IMG_1232.jpg" file that Franklin52's awk command creates in my case; I inserted a "begin 666 IMG_1232.jpg" line in front of the uuencoded data. But that just caused uudecode to fail:
Apparently uudecode reads part of its input file ("IMG_1232.jpg" in this case), then writes out the decoded data to the specified filename ("IMG_1232.jpg" again), then tries to read the next chunk of uuencoded data, but can't because it has just clobbered its (longer) source file with its (short partial) output, so it screams "IMG_1232.jpg: Short file" and dies.
So while the awk script is interesting, it is not a solution to my issue. Sorry Franklin52. Happily, I've already got a fully working solution, thanks to unilover's input.
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)
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)
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 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)
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,
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)
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)
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)