Apply to end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Apply to end of line
# 1  
Old 07-12-2005
Apply to end of line

Heyo all,
I'm working on a script to generate some simple web based statistics for a project I'm on. I'm ending up with the following lines that follow the same basic format:

SYSTEM.ADMIN.PERFM.EVENT 0
SYSTEM.ADMIN.QMGR.EVENT 1
SYSTEM.AUTH.DATA.QUEUE 28
SYSTEM.CHANNEL.INITQ 0
SYSTEM.CHANNEL.SYNCQ 0

I'm trying to find a way to take the numbers at the end of each line, and be able to apply a modification to them. For example:
SYSTEM.AUTH.DATA.QUEUE 28 - becomes - SYSTEM.AUTH.DATA.QUEUE <b>28</b> to highlight the number in bold letters on the page.

I'm racking my brain trying to find an efficient way to pull it off. Any suggestions would rule. Thanks as always. Smilie
# 2  
Old 07-12-2005
gnu awk:
Code:
awk '$2="<b>"$2"</b>"' old.html >new.html

# 3  
Old 07-12-2005
Quote:
Originally Posted by r2007
gnu awk:
Code:
awk '$2="<b>"$2"</b>"' old.html >new.html

This works absolutely great, thank you very much for the example.

I'm under the assumption that the $2 is going after the second field? If so, for example, some of my lines are as follows, with an additional number:

SYSTEM.CLUSTER.COMMAND.QUEUE 0 1

I would think I could do: awk '$3="<b>"$3"</b> to highlight that last number as well. I've tried it and it doesn't seem to work as the awk manuals suggests for the third field. Any ideas?

Thanks again. Smilie
# 4  
Old 07-12-2005
except the 1st field, rest of fields will be highlight with <b> tag.
try:
Code:
awk '{for(i=2;i<=NF;i++)$i="<b>"$i"</b>";print}'

# 5  
Old 07-12-2005
Quote:
Originally Posted by r2007
except the 1st field, rest of fields will be highlight with <b> tag.
try:
Code:
awk '{for(i=2;i<=NF;i++)$i="<b>"$i"</b>";print}'

Weird, going over this piece by piece, it should work, as I believe $3 should, but I think for some reason awk isn't able to read the input data as I'm seeing it. Sort of strange.

Thank you for the extra help. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

3. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

4. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

5. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

6. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

7. Shell Programming and Scripting

adding characters end of line where line begins with..

Hi all, using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg a,b,c,......., r,s,t,........, a,b,c,......., all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the... (6 Replies)
Discussion started by: satnamx
6 Replies

8. Shell Programming and Scripting

Apply 'awk' to all files in a directory or individual files from a command line

Hi All, I am using the awk command to replace ',' by '\t' (tabs) in a csv file. I would like to apply this to all .csv files in a directory and create .txt files with the tabs. How would I do this in a script? I have the following script called "csvtabs": awk 'BEGIN { FS... (4 Replies)
Discussion started by: ScKaSx
4 Replies

9. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

10. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies
Login or Register to Ask a Question