Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Look for strings and use variables Post 302564693 by CarloM on Friday 14th of October 2011 10:53:55 AM
Old 10-14-2011
Quote:
Originally Posted by Benou
Also, I have been trying to understand how the nawk command you posted works but it looks like chinese to me. Would you mind giving me a short explanation.
Code:
nawk -F"[\",]" '/MARK/||/GET/ {print $2,$9}' infile | cut -d' ' -f2

Thanks so much.
Ben
nawk -F"[\",]" Use double-quote and comma as (input) field separators. (Line 1 field 1 is now '--MARK--', field 2 is blank, field 3 is 'Thu Oct 13... ' etc).
/MARK/||/GET/ For lines containing MARK or GET...
{print $2,$9} print field 2 and field 9. Note that for some lines these are empty strings.

With some square brackets to (hopefully) make the output a bit clearer, this is what comes out of the (n)awk command:
Code:
# awk -F"[\",]" '/MARK/||/GET/ {printf ("[%s] [%s]\n", $2, $9)}' xx.txt
[] [192.168.230.1]
[GET /Webcam/webcam.html HTTP/1.1] []
[] []
[] [192.168.230.1]
[GET /cgi-bin/camctrl.cgi HTTP/1.1] []
[] []

This is then piped into:
cut -d' ' cut with a field delimiter of space
-f2 and output field 2.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need assistance with appending strings using sed and variables

HI, Can't seem to find anything on the forums to fix this. I have a file, one line within this will not have a specific string at the end. I have the string, but need to append it to the specific line which has it missing. I need to use a variable for this, $string - I am using double... (13 Replies)
Discussion started by: mandriver
13 Replies

2. Shell Programming and Scripting

assign colon delimited strings to variables

Man it has been too long since I have had to do this type of stuff... OK I have a file with lines in it looking like this: bob:johnson:email@email.com (most lines) john:F.:doe:email2@email.com (but some are like this) I need to loop through and assign vars to the values: var Fname =... (29 Replies)
Discussion started by: NewSolarisAdmin
29 Replies

3. Shell Programming and Scripting

replace two character strings by two variables with sed command

Hello, I want to writte a script that replace two character strings by two variables with the command sed butmy solution doesn't work. I'm written this: sed "s/TTFactivevent/$TTFav/g && s/switchSLL/$SLL/g" templatefile. I want to replace TTFactivevent by the variable $TTFav, that is a... (4 Replies)
Discussion started by: POPO10
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] take name of directory and files as variables

hi, want to create script that takes name of directory and all files and will copy each file to new directory. then fix errors like files do not exist or no permission to create new directory... these what I have so far... #!/bin/sh dir=~/Documents/Scripts/Copy for i in $(pwd) $(ls)... (23 Replies)
Discussion started by: me.
23 Replies

5. Shell Programming and Scripting

[Solved] Bash test 2 variables to see if ones greater by n

Experts, I have a bash shell script that generates 2 variables that have the current minute and a minute from a log file. Can someone please show me the best way to test if the minutes stray by 5. So basically if: This is ok: Last Fitting Min ============= 02 Current Minute =============... (2 Replies)
Discussion started by: jaysunn
2 Replies

6. Shell Programming and Scripting

[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue. Working with date is quite simple, so if I Need to add some seconds to current time, I'll use: date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"But, how to pass the value to add from a variable? I tried the following without... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

7. Shell Programming and Scripting

[solved] Question for using variables outside a while loop

I want to get newvar outside the while any ideas? while read myline; do var=${myline} newvar1=$(let "$var") done echo $newvar1 I found it its ok now Thank you! (0 Replies)
Discussion started by: sanantonio7777
0 Replies

8. Shell Programming and Scripting

[SOLVED] nawk FS using pipe read variables from file

I have a file data_1.out which contains: 1|abc mail|mail subject|mail body 2|def mail|mail subject|def mail body I am trying to read the variables from data_1.out and use them to print to 2 different files based on the id (first_column) The problem is I am not able to read the file... (8 Replies)
Discussion started by: sol_nov
8 Replies

9. Homework & Coursework Questions

[solved]Perl: Printing line numbers to matched strings and hashes.

Florida State University, Tallahassee, FL, USA, Dr. Whalley, COP4342 Unix Tools. This program takes much of my previous assignment but adds the functionality of printing the concatenated line numbers found within the input. Sample input from <> operator: Hello World This is hello a sample... (2 Replies)
Discussion started by: D2K
2 Replies

10. UNIX for Dummies Questions & Answers

Adding variables to repeating strings

Hello, I want to add a letter to the end of a string if it repeats in a column. so if I have a file like this: DOG001 DOG0023 DOG004 DOG001 DOG0023 DOG001 the output should look like this: DOG001-a DOG0023-a DOG004 DOG001-b (15 Replies)
Discussion started by: verse123
15 Replies
page_util_flow(n)					      Parser generator tools						 page_util_flow(n)

__________________________________________________________________________________________________________________________________________________

NAME
page_util_flow - page dataflow/treewalker utility SYNOPSIS
package require page::util::flow ?0.1? package require snit ::page::util::flow start flowvar nodevar script flow visit node flow visitl nodelist flow visita node... _________________________________________________________________ DESCRIPTION
This package provides a single utility command for easy dataflow based manipulation of arbitrary data structures, especially abstract syn- tax trees. API
::page::util::flow start flowvar nodevar script This command contains the core logic to drive the walking of an arbitrary data structure which can partitioned into separate parts. Examples of such structures are trees and graphs. The command makes no assumptions at all about the API of the structure to be walked, except that that its parts, here called nodes, are identified by strings. These strings are taken as is, from the arguments, and the body, and handed back to the body, without modification. Access to the actual data structure, and all decisions regarding which nodes to visit in what order are delegated to the body of the loop, i.e. the script. The body is invoked first for the nodes in the start-set specified via start), and from then on for the nodes the body has requested to be visited. The command stops when the set of nodes to visit becomes empty. Note that a node can be visited more than once. The body has complete control about this. The body is invoked in the context of the caller. The variable named by nodevar will be set to the current node, and the variable named by flowvar will be set to the command of the flow object through which the body can request the nodes to visit next. The API provided by this object is described in the next section, FLOW API. Note that the command makes no promises regarding the order in which nodes are visited, excpt that the nodes requested to be visited by the current iteration will be visited afterward, in some order. FLOW API
This section describes the API provided by the flow object made accessible to the body script of ::page::util::flow. flow visit node Invoking this method requests that the node n is visited after the current iteration. flow visitl nodelist Invoking this method requests that all the nodes found in the list nodelist are visited after the current iteration. flow visita node... This is the variadic arguments form of the method visitl, see above. BUGS, IDEAS, FEEDBACK This document, will undoubtedly contain bugs and other problems. Please report such in the category page of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have. KEYWORDS
dataflow, graph walking, page, parser generator, text processing, tree walking CATEGORY
Page Parser Generator COPYRIGHT
Copyright (c) 2007 Andreas Kupries <andreas_kupries@users.sourceforge.net> page 1.0 page_util_flow(n)
All times are GMT -4. The time now is 09:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy