To Add input to lastline of the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Add input to lastline of the script
# 1  
Old 03-04-2010
Question To Add input to lastline of the script

I have written some script that gives a html table output .But i cant add a line to the last line.The line should be like
----------------------------------------------------------
Generated at `system date and time`

Below is the script for your refernce.i want ti display the last line in italic

Code:
awk -v border=1 -v width=10 -v bgcolor=black -v fgcolor=white '
BEGIN { printf("<table border=\"%d\" bordercolor=\"%s\" width=\"%d\" bgcolor=\"%s\"\n>",border,bgcolor,width,fgcolor)
        printf("<th>Hostname</th><th>Volstat</th><th>Pairstat</th>\n")
}
{
print "<tr>";
        for( i = 1 ; i <= NF ; ++i )
                print "<td> "$i" </td>"
        print "</tr>"
}
END {  print "</table>" }'  /tmp/offshore/out/11.csv

Below are the ouput of script



Code:
><th>Hostname</th><th>Volstat</th><th>Pairstat</th>
<tr>
<td> chilgtp03 </td>
<td> SVOLstatus </td>
<td> SSUS </td>
</tr>
<tr>
<td> chilgtp02 </td>
<td> SVOLstatus </td>
<td> SSUS </td>
</tr>
<tr>
<td> sdclgtp04 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> SigmaIota </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> up81056 </td>
<td> SVOLstatus </td>
<td> PSUE </td>
</tr>
<tr>
<td> up81043 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> up2003 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> up1061ab </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> up1218 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> up1126 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
<tr>
<td> uchipf053dmp </td>
<td> SVOLstatus </td>
<td> PSUE </td>
</tr>
<tr>
<td> up1242ab </td>
<td> PVOLstatus </td>
<td> PSUE </td>
</tr>
<tr>
<td> up1554 </td>
<td> PVOLstatus </td>
<td> PSUS </td>
</tr>
</table>


Thanks for reading this thread

Last edited by pludi; 03-04-2010 at 03:52 PM.. Reason: code tags, please...
# 2  
Old 03-04-2010
How exactly do you expect the last line, I mean, could you write an example out as you want it?
# 3  
Old 03-04-2010
Helo, zeebala1981

The following will print out "<i>Generated at date_output</i>". If that's what you're looking for, you can take those two lines and insert them into the proper place in your code.
Code:
awk 'BEGIN{"date" | getline d; print "<i>Generated at " d "</i>"}'

Alister
# 4  
Old 03-04-2010
Alister iam getting following error



Code:
awk: cmd. line:3:       printf("date" | getline d: print  "<i>Generated at " d "</i>")
awk: cmd. line:3:                                ^ parse error

# 5  
Old 03-04-2010
Quote:
Originally Posted by zeebala1981
Alister iam getting following error
Code:
awk: cmd. line:3:       printf("date" | getline d: print  "<i>Generated at " d "</i>")
awk: cmd. line:3:                                ^ parse error

It should be a semicolon, ";", not a colon, ":". However, even with the correct statement delimiter, that's not a valid expression argument. You want something along the lines of:
Code:
"date" | getline d
printf("<i>Generated at %s</i>", d)

or perhaps the much less readable but slightly more featureful (returns "ERR" if the command fails) though not necessarily more useful:
Code:
printf("<i>Generated at %s</i>\n", ("date 2>/dev/null" | getline d)==1 ? d : "ERR")

Note that if you are going to call this more than once, you need to close "date" or "date 2>/dev/null" between iterations.

Alister

Last edited by alister; 03-04-2010 at 06:04 PM..
# 6  
Old 03-04-2010
Code:
echo "Generated at `date`" >> /tmp/offshore/out/11.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to add +1 to value based on condition in input

In the awk below I am trying to add a | that will adjust $2 in the ouput by adding +1 if the original value from file that was used in $3 had a - in it. Line 3 of file is an example of this. In my current awk I just subtract one but I am not sure how to only apply this to those values without a -.... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies

3. Shell Programming and Scripting

Add input to text file

In the attached bash file I am trying to add a block of code to add2text that will copy the input from match to a text file (file.txt). For example, if from the menu choice 1 is select the user is asked for the id.... lets say that is 12345, after that id is matched and converted can it be added... (22 Replies)
Discussion started by: cmccabe
22 Replies

4. Shell Programming and Scripting

How to input parameters and add Columns?

Hello and good day I am not familiar with programming. I have text files and I would like to: 1) edit script to input "a" and "b" parameters by users 2)put input directories in loop : Something like this: Ex: For i in /usr/desktop/input/SG* 3)add 2 more columns and performing... (2 Replies)
Discussion started by: ali.seifaddini
2 Replies

5. UNIX for Dummies Questions & Answers

Find and add a field for an input file

Hello Sir/Madam, I'm new to UNIX and wondering if I can process a find & add using AWK command in UNIX? requirements: I have to find *.JPG field for each line in the input file and add it as a separate field for each line.. for ex: 0000684631,E,3088017,7... (10 Replies)
Discussion started by: V1l1h1
10 Replies

6. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

7. Shell Programming and Scripting

shell script to add input at certain location into a file

Hi, I am using Solaris 10 OS and trying to create shell script that can add input at certain location into a file. The input that I am trying to put is new domain name e.g @newdomain.com the file contains, more test01.out user/zzzz786@st.com/INBOX user/zzzz@po.com/INBOX... (8 Replies)
Discussion started by: Mr_47
8 Replies

8. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

9. UNIX for Dummies Questions & Answers

input a float data and add them in shell in linux

I want to input a float data and add them in shell in linux. I am new user of it can anyone tell me how I can do it? thanx (5 Replies)
Discussion started by: purva
5 Replies

10. UNIX for Dummies Questions & Answers

add new lines of text before and after each input line

I have a file that contains hundreds of lines such as: this_is_macro,000001 this_is_macro,000002 this_is_macro,000003 I would like to add the variable words MACROBEGIN MACRO_000001 MACROBEGIN MACRO_000002 MACROBEGIN MACRO_000003 above each line and add the word MACROEND ... (2 Replies)
Discussion started by: kenneth.mcbride
2 Replies
Login or Register to Ask a Question