AWK / tail Issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK / tail Issue
# 1  
Old 01-16-2011
Tools 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:
Code:
11-01-16 11:55:45.174 | CClientObject::InitTraceLevelInCache Starting 
CClientObject::InitTraceLevelInCache End

I am doing a awk statement to gather only the numeric values:
Code:
tmp_tail=`tail -2 "$trace" | awk '{print $1$2}' | cut -f,1 -d '.' | tr -d '-' | tr -d ':'`

output:
Code:
110116115545
CClientObjectInitTraceLevelInCacheEnd

I want only the output for the line before last --> i.e. 110116115545

Please assist.

Last edited by Scott; 01-16-2011 at 09:05 AM.. Reason: Please use code tags
# 2  
Old 01-16-2011
As you seem to be having fun with pipes, what harm would another one do?

Code:
tmp_tail=$(tail -2 ...... | head -1)

Some sed (which I'm sure could be simplified):
Code:
$ sed -n '${g;s/\..*//;s/[^0-9]//g;p;};h' file
110116115545

These 2 Users Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to tail sed and awk in one line?

Hello, I am trying to create an iptables script with tail ,sed and awk. 1st Request: Search keyword "secret" in access.log file 2nd Request: Get first column matching lines (ip address) 3rd Request: Save it to a file This is what I did so far: grep.sh #!/bin/bash while true; do tail... (23 Replies)
Discussion started by: baris35
23 Replies

2. How to Post in the The UNIX and Linux Forums

Usage of tail command in .awk

Hi, I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as... (3 Replies)
Discussion started by: Venkata Madhu
3 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Tail command issue in Linux

Hello, When I am trying to use tail +13 filename.csv it is throwing an error. tail: cannot open `+13' for reading: No such file or directory and then prints last 10 lines of the file. (File is present on the path) But when i try tail -13 filename.csv it runs perfectly. Could I have... (5 Replies)
Discussion started by: AnkitSenghani
5 Replies

4. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

5. Shell Programming and Scripting

tail issue!

Hi, I had few scripts which were running fine on linux: uname -a Linux ######### 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:33:05 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux from some front end application. Recently there was a migration of this application on some other linux m/c: uname -a... (4 Replies)
Discussion started by: dips_ag
4 Replies

6. Shell Programming and Scripting

Averaging in increments using awk & head/tail

Hi, I only have a very limited understanding and experience with writing code and I was hoping I could get some help. I have a dataset of two columns (txt format, numbers in each row separated by a tab) Eg. 1 5 2 5 3 6 4 7 5 6 6 6 7 ... (5 Replies)
Discussion started by: Emred_Skye
5 Replies

7. Shell Programming and Scripting

Issue Filtering Tail

Hi Folks, I have a log that contains data as shown below: 11:59:43,144 (1,850) Signal : .... 11:59:44,109 (1850) Bps : ..... I wish to remove "" from all lines and it is on the start of every line. I have achieved that successfully using the command: tail -f imp.log | sed 's/\... (4 Replies)
Discussion started by: umairrahman
4 Replies

8. UNIX for Dummies Questions & Answers

AWK Output not working with tail -f

Hi , I have Continuous updating log file. I want to continuously scan that file using "tail -f " and execute a shell command like "date" command when that particular keyword is detected . I am using awk to acheive it but not suceeded so far. However when I use "cat" instead of tail -f this... (3 Replies)
Discussion started by: scott_tiger
3 Replies

9. Shell Programming and Scripting

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

Hello, I am too daft to remember how to properly feed numbers that I've extracted with awk(1) to tail(1). The actual question is probably a lot more simple than the context, but let me give you the context anyway: I've just received some email that was sent with MS Outlook and arrived in... (8 Replies)
Discussion started by: ropers
8 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