Sponsored Content
Top Forums Shell Programming and Scripting Modify line with dynamic variable in awk Post 302576538 by clx on Friday 25th of November 2011 06:56:44 AM
Old 11-25-2011
Your first line of the expected output contains "10/13/2011" which is wrong I guess.

Code:
awk '/TIMESTAMP/ {t=$4}{print t,$0}' file

O/P
Code:
10/13/2011 3:03:35 (lmgrd) TIMESTAMP 10/13/2011
10/13/2011 3:20:41 (MLM) IN: "MATLAB" user1@host1.private.dns.zone
10/13/2011 3:21:05 (MLM) IN: "MATLAB" user1@host2.private.dns.zone
10/13/2011 5:00:33 (MLM) IN: "MATLAB" User@host3
10/13/2011 5:48:48 (MLM) IN: "MATLAB" user2@host3.private.dns.zone
10/14/2011 6:06:47 (MLM) TIMESTAMP 10/14/2011
10/14/2011 6:13:15 (MLM) IN: "MATLAB" user2@host2.private.dns.zone
10/15/2011 1:02:47 (MLM) TIMESTAMP 10/15/2011
10/15/2011 1:14:15 (MLM) IN: "MATLAB" user3@host2.private.dns.zone


Please use code tags next time.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to modify the variable

I have a directory name stored in a variable. Does anyone have a piece of code which checks if this stored directory name ends up with the "/" and if it is missing adds it to the same variable. for example I might have A=/bb/data or A=/bb/data/ which needs to be A=/bb/data/ for sure thanks... (5 Replies)
Discussion started by: aoussenko
5 Replies

2. Shell Programming and Scripting

how to modify the value of the variable

Hi I have a variable which holds full path to the file, for example z=/bb/data3/f4222pdb.dta.new I need to remove the extension .new so it would look like z=/bb/data3/f4222pdb.dta Is there a command to do this? This variable is used in the "for" loop later. I am in ksh. Thanks a lot -A (4 Replies)
Discussion started by: aoussenko
4 Replies

3. Shell Programming and Scripting

print any required line by its line no using awk and its NR variable

how to print any required line by its line no using awk and its NR variable for eg: ------------ 121343 adfdafd 21213sds dafadfe432 adf.adf%adf --------------- requied o/p if give num=3 it print: 21213sds -------------------------------------- (2 Replies)
Discussion started by: RahulJoshi
2 Replies

4. Shell Programming and Scripting

Dynamic command line generation with awk

Hi, I'm not an expert in awk but i need a simple script to do this: I'd like to AutoCrop PDF files. I found 2 simple script that combined together could help me to automatize :) The first utiliti is "pdfinfo" that it gives the MediaBox and TrimBox values from the pdf. The pdfinfo output... (8 Replies)
Discussion started by: gbagagli
8 Replies

5. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

6. Shell Programming and Scripting

awk line variable help

I am using Solaris 10 and have no GNU products installed. I have the following awk code and would like to add a variable. I believe awk doesn't accept variables, but I think nawk can. I would like to replace the red higlighted part of my code with a variable. If nawk is the answer how do I change... (3 Replies)
Discussion started by: thibodc
3 Replies

7. Shell Programming and Scripting

Using AWK to get a specific line using a variable

Hi I have a text like this example.input 1 red 2 blue 3 green If I set this c=2 Then try awk 'NR==$c { print $2 }' example.input I do get nothing If I try awk 'NR==2 { print $2 }' example.input i get blue (8 Replies)
Discussion started by: Jotne
8 Replies

8. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

9. Shell Programming and Scripting

Passing dynamic variable within another variable.

I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable. ***************** Program Start ****************** LOC1=/loc1 PAT1IN=/loc2 PAT2IN=/loc3 if ; then for fpattern in `cat... (5 Replies)
Discussion started by: Cyril Jos
5 Replies

10. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies
TUTORIALS(1p)						User Contributed Perl Documentation					     TUTORIALS(1p)

NAME
PDL::Tutorials - A guide to PDL's tutorial documentation. MIGRATION
These are our migration guides for users familiar with other types of numerical analysis software. PDL::MATLAB Migration guide for MATLAB users. This page explains the key differences between MATLAB and PDL from the point of view of a MATLAB user. PDL::Scilab Migration guide for Scilab users. This page explains the key differences between Scilab and PDL from the point of view of a Scilab user. FOUNDATION
PDL::Philosophy Why did we write PDL? This document explains some of the history and motivation behind the Perl Data Language. It is an attempt to answer the question "Why PDL?". PDL::QuickStart Quick introduction to PDL features. A hands-on guide suitable for complete beginners. This page assumes no previous knowledge of Perl or PDL. PDL::Indexing After you have read the QuickStart guide, you should follow up with this document. This guide goes more deeply into the concepts of "indexing" and "slicing" and how they form the core of numerical analysis with PDL. INTERMEDIATE
PDL::Threading Threading is one of PDL's most powerful features. If you know MATLAB, you've heard of "vectorizing". Well, threading is like "vectorizing on steroids". It lets you make very fast and compact code by avoiding nested loops. All vector-based languages do this, but PDL generalizes the technique to all sorts of applications. This tutorial introduces PDL's threading feature, and it shows an example implementing Conway's Game of Life in 10 lines and 80 times faster than a classical implementation. PDL::BadValues Sometimes it is useful to specify that a certain value is "bad" or "missing". Scientific instruments some times include portions of invalid data. For example, a CCD camera might produce an image with over-exposed pixels. PDL's "bad values" feature gives you an easy way to deal with this sort of imperfect data. PDL::Tips Tips and suggestions for using PDL. This page is an assorted collection of programming tidbits that some PDL users have found useful. Some of these tips might be of help when you write your programs. ADVANCED
PDL::PP PDL's Pre-Processor is one of PDL's most powerful features. You write a function definition in special markup and the preprocessor generates real C code which can be compiled. With PDL:PP you get the full speed of native C code without having to deal with the full complexity of the C language. PDL::API A simple cookbook explaining how to create piddle manually, either from Perl or from C/XS code. This page covers the PDL core routines that comprise the PDL API. If you need to access piddles from C/XS, this is the document for you. PDL::Internals Description of the inner workings of the PDL module. Very few people need to see this. This page is mainly for PDL developers, or people interested in debugging PDL or changing the internals of PDL. If you can read this document and understand all of it, and you additionally understand PDL::PP, you will be awarded the title of "PDL Guru". COPYRIGHT
Copyright 2010 Daniel Carrera (dcarrera@gmail.com). You can distribute and/or modify this document under the same terms as the current Perl license. See: http://dev.perl.org/licenses/ perl v5.14.2 2012-01-02 TUTORIALS(1p)
All times are GMT -4. The time now is 09:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy