How do I feed numbers from awk(1) to tail(1)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I feed numbers from awk(1) to tail(1)?
# 8  
Old 04-04-2008
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:
Code:
awk '/begin 666/{f=1;close("name");name=$3;next}f{print > name}' /tmp/tmp.mail

That means /tmp/tmp.mail is used as input for the
Code:
/begin 666/{f=1;close("name");name=$3;next}f{print > name}

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):
Code:
$ uudecode IMG_1183.jpg 
uudecode: IMG_1183.jpg: No `begin' line

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:
Code:
$ uudecode IMG_1232.jpg
uudecode: IMG_1232.jpg: Short file

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. Smilie Happily, I've already got a fully working solution, thanks to unilover's input. Smilie

Last edited by ropers; 04-06-2008 at 09:29 AM..
# 9  
Old 04-05-2008
Well, with the given approach, it should be challenge for you to make it works.Smilie

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to tail a file with unknown numbers

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)
Discussion started by: encrypt_decrypt
9 Replies

2. UNIX for Beginners Questions & Answers

awk Command to add Carriage Return and Line Feed

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)
Discussion started by: rosebud123
16 Replies

3. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

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)
Discussion started by: pchang
8 Replies

4. Shell Programming and Scripting

awk for replacing line feed

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)
Discussion started by: lokaish23
10 Replies

5. Shell Programming and Scripting

Unix, awk to read .ksh feed

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)
Discussion started by: INHF
3 Replies

6. Shell Programming and Scripting

awk remove line feed

Hi, I've this file: 1, 2, 3, 4, 5, 6, I need to remove the line feed LF every 3 row. 1,2,3, 4,5,6, Thanks in advance, Alfredo (5 Replies)
Discussion started by: alfreale
5 Replies

7. Shell Programming and Scripting

AWK / tail Issue

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)
Discussion started by: LiorAmitai
1 Replies

8. Shell Programming and Scripting

Extract URL from RSS Feed in AWK

Hi, I have following data file; <outline title="Matt Cutts" type="rss" version="RSS" xmlUrl="http://www.mattcutts.com/blog/feed/" htmlUrl="http://www.mattcutts.com/blog"/> <outline title="Stone" text="Stone" type="rss" version="RSS" xmlUrl="http://feeds.feedburner.com/STC-Art"... (8 Replies)
Discussion started by: fahdmirza
8 Replies

9. Shell Programming and Scripting

replace last form feed with line feed

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)
Discussion started by: prvnrk
5 Replies

10. Shell Programming and Scripting

Tail -f, awk and redirection

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)
Discussion started by: mfajer
2 Replies
Login or Register to Ask a Question