Formating text from a script into a log file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Formating text from a script into a log file
# 1  
Old 06-30-2005
Formating text from a script into a log file

Using a for loop I am able to get the following log file below. I would like o change the format a bit as is indicated lower down. I have looked at awk and sed but somehow is not getting any joy. I am a bit new to ksh scripting. Please assist.

This is the format of my current log file after the script has run.

/edi/iTracTEST/sessions/otherreceive/nohup.out @ 08:19:46 from 63 - 63
/edi/iTracTEST/sessions/payroll/nohup.out @ 08:19:46 from 52395 - 63
/edi/iTracTEST/sessions/payrollmsg/nohup.out @ 08:19:46 from 56931 - 63

As from the first record/line.
The path and file name is already in a variable from a the for loop in the script.
The "@" is echoed.
The time is coming from the date command.
The "from" is echoed.
The first 63 is the initial file size in bytes as from a variable in the for loop.
The "-" is echoed.
The second 63 is the current/new file size as from a variable in the for loop.

I would like the log file to look like this. !!!Notice I have swapped the sizes!!!

/edi/iTracTEST/sessions/otherreceive/nohup.out 08:19:46 63 63
/edi/iTracTEST/sessions/payroll/nohup.out 08:19:46 63 52395
/edi/iTracTEST/sessions/payrollmsg/nohup.out 08:19:46 63 56931

This just make the log file more readable.
Here is some of the code, thus far.

sess_path=/edi/iTracTEST/sessions/
ls -pl /edi/iTracTEST/sessions/ | awk '$1 ~ /^d/ $9 ~ /\/$/' | awk '{print $9}' > `pwd`/temp/`date +"%C%y%m%d"`.tmp
for nohup_loc in $(cat `pwd`/temp/`date +"%C%y%m%d"`.tmp)
do
nohup_loc2=$sess_path$nohup_loc"nohup.out"
if test -s $nohup_loc2
then
cur_fsize=`ls -l $nohup_loc2 | awk '{print $5}'`
echo !!! Reset nohup.out file at `date` !!! > $nohup_loc2
new_fsize=`ls -l $nohup_loc2 | awk '{print $5}'`
echo $nohup_loc2 @ `date +%H:%M:%S` from $cur_fsize - $new_fsize >> `pwd`/log/`date +"%C%y%m%d"`_nohup_reset.log
fi
done
# 2  
Old 06-30-2005
MySQL Try This :-

Quote:
Originally Posted by hugow

echo $nohup_loc2 @ `date +%H:%M:%S` from $cur_fsize - $new_fsize >> `pwd`/log/`date +"%C%y%m%d"`_nohup_reset.log
fi

done
In the " echo " where u get the final output use this :

echo $nohup_loc2 @ `date +%H:%M:%S` from $cur_fsize - $new_fsize | awk '{tmp=$5;$5=$7;$7=tmp;print $0}'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File formating

I need to create a fixed width file based on the column lengths. lets assume I have six(this may be dynamic) fields each are of different length column1=6 #size of the column column2=3 column3=2 column4=3 column5=4 column6=5 I tried below code snippet but it is not working echo... (4 Replies)
Discussion started by: gvkumar25
4 Replies

2. UNIX for Beginners Questions & Answers

File formating help

Hi all, I am having the file below I need that as below Thanks, Arun (12 Replies)
Discussion started by: arunkumar_mca
12 Replies

3. UNIX for Beginners Questions & Answers

File formating with lines

Hi All, Need to modify a file basically join the extra line to one I am having a file like below And would like to make it as below . (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

4. Shell Programming and Scripting

Text Formating or Modifying

Hi Experts, I have a text exactly like below in a file: id item_id item_date prin_mkt_val --------------------------- --------------------------- ------------------------------- ------------------------ ... (1 Reply)
Discussion started by: apatil65
1 Replies

5. Shell Programming and Scripting

Text formating issue

Hi, I am trying to format the output of my script in a tabular format using the html code in my shell script. I am using html code for the first time in a shell script.I am trying to execute this script in Ksh but it is not getting executed. Can you please help me in figuring this out.... (6 Replies)
Discussion started by: isaacsam
6 Replies

6. Shell Programming and Scripting

Text formating

Dear all I had input file as mention below and want op as mention. Kindly let me knw possible ways. Regards Jaydeep INPUT: RXOTX-48-1 2A 34 2B 35 RXOTX-499-2 2C 32 RXOTX-4-1 2D 23 OUTPUT: (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

7. Shell Programming and Scripting

TEXT formating using script

Dear All I am facing problem while extracting data from below mention input file. My op should be like this.Required field display in red in file. Request you all to help. OP: RXOTX-46-5 1B4 RXOTX-46-4 2B5 INPUT FILE: <RXMFP:MO=RXOTX-46-5; RADIO X-CEIVER ADMINISTRATION... (4 Replies)
Discussion started by: jaydeep_sadaria
4 Replies

8. UNIX for Dummies Questions & Answers

Help required on file formating

I have two files file1 and file2 as shown below: file1: name nameabc bcd nameabcdefg file2: age age1111 age2345 age6743 I have pasted one file on the other with the delimiter "|" and the resulttant file is: name|age nameabc|age1111 bcd|age2345 nameabcdefg|age6743 (1 Reply)
Discussion started by: udiptya
1 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Formating mailx text file for Lotus Notes users

We use AIX mailx or sendmail. How can I format a text file so that lotus notes users can see diferent fonts and highlighting. Or can a gif file (company logo..) be sent along with a text file and the Lotus notes user would see the logo and text displayed at the same time and not as an attachment? (0 Replies)
Discussion started by: lidoiwo
0 Replies

10. UNIX for Dummies Questions & Answers

text formating/Text space padding

Hi, How do I format the following? I have a for loop that retrieves me the path and file name of a file. In column fashion I would like to add the time and another variable containing the file's size. This will result in all the time being under each other and all the file size's being under... (6 Replies)
Discussion started by: hugow
6 Replies
Login or Register to Ask a Question