Sponsored Content
Full Discussion: Basic awk help
Top Forums UNIX for Dummies Questions & Answers Basic awk help Post 302774719 by Don Cragun on Sunday 3rd of March 2013 01:05:43 AM
Old 03-03-2013
Each call to print produces a <newline> character in the output. You could try something like:
Code:
awk '/AP/{sub(/:80/, "", $4);printf "%s\t", $4} /User-Agent/{sub(/^[^:][^:]*:/,"");printf "%s\t", $0}/Host/{sub(/^[^:][^:]*:/,"");print}'

Note that I changed the format string for your printf call. If $4 happens to contain any % or \ characters, you could end up with output significantly different from what you might expect; using the format %s avoids that possibility.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk basic issue

Hi all, I have an awk basic question. file.text Our Location: Our home has light yellow siding, and is a duplex on Main Street, across from the High School, and across the lane from the Health Center If I run: cat file.txt | awk '{print $2}' | grep... (7 Replies)
Discussion started by: research3
7 Replies

2. UNIX for Dummies Questions & Answers

Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk. This is the contents of test.sh awk '{print $1}' From the prompt if I enter: ./test.sh Hello World I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Discussion started by: JasonHamm
2 Replies

3. Shell Programming and Scripting

basic awk questions

I find an script with awk sitting around. I went through some online manuals, but I can't figure out exactly how it works. I can't post the whole program. Not allowed. This is the line that is confusing me. I get when else is in the script grep -v "^REM " $1| grep -v "JUNK;" | awk -F" "... (2 Replies)
Discussion started by: guessingo
2 Replies

4. Shell Programming and Scripting

Issue with basic Awk script

Here's a basic awk program I am trying to run. It shows no error but shows no result either too. If someone can look up and tell me what's wrong I will be obliged. Thanks. :) Code Snippet. #!/bin/bash awk '{ for (i = 1 ; i <= 3 ; i++) for ( j = 1 ; j <= 3 ; j++ ) { ... (2 Replies)
Discussion started by: mr.amitkc
2 Replies

5. UNIX for Dummies Questions & Answers

Basic loop awk/shell script question..

Hi, Sorry if this is a newbie question. I guess you can use either awk or shell script for this sequence of operations, but knowing very little about either of them I'm not sure how I should try to write this. The basic objective is to copy certain files that are scattered all over my... (10 Replies)
Discussion started by: pc2001
10 Replies

6. UNIX for Dummies Questions & Answers

Basic awk...newbie quetion

Hi, I was trying to change the value of the 4th column (put '1' in the 4th column of each row). My awk command is: awk -F, '{$3=1;}1' OFS= input.txt > ./test_out.txt My input file is: a 1 2 31 b 4 5 61 c 7 8 91 My output file (test_out.txt)is: a 1 2 31 b 4 5 61 c 7 8 91 What... (4 Replies)
Discussion started by: pc2001
4 Replies

7. UNIX for Dummies Questions & Answers

Basic arithmetic operation with awk?

input: Name|Operation rec_10|1+2+2- Output: rec_10|1 Basically I am trying to calculate the result of "the path" in $3 where the operators follow the number and not preceding them like we normally do: rec_10: +1+2-2=1 But I realise (I am sure there is a good reason for that) that awk... (7 Replies)
Discussion started by: beca123456
7 Replies

8. Shell Programming and Scripting

Confusing of some basic awk

1. increase file space first, double space a file: awk '1;{print ""}' I probably can understand it:print a blank line every time.But when I read triple space a file I am confused: awk '1;{print "\n"}' doesn't it meaning print a blank line every time too? 2. number each line of file, but... (6 Replies)
Discussion started by: hhdzhu
6 Replies
printf(3int)															      printf(3int)

Name
       printf, fprintf, sprintf - print formatted output

Syntax
       #include <stdio.h>

       int printf ( format [, arg ] ...  )
       char *format;

       int fprintf ( stream, format [, arg ] ...  )
       FILE *stream;
       char *format;

       int sprintf ( s, format [, arg ] ...  )
       char *s, *format;

Description
       The  international functions and are similar to the standard I/O functions. The difference is that the international functions allow you to
       use the %digit$ conversion character in place of the % character you use in the standard I/O functions. The digit is a decimal digit n from
       1 to 9.	The international functions apply conversions to the n th argument in the argument list, rather than to the next unused argument.

       You can use the % conversion character in the international functions.  However, you cannot mix the % conversion character with the %digit$
       conversion character in a single call.

       You can indicate a field width or precision by an asterisk (*) instead of a digit string in format  strings  containing	the  %	conversion
       character.  If you use an asterisk, you can supply an integer arg that specifies the field width or precision. In format strings containing
       the %digit$ conversion character, you can indicate field width or precision by the sequence *digit$.  You use a decimal digit from 1  to  9
       to indicate which argument contains an integer that specifies the field width or precision.

       The conversion characters and their meanings are identical to

       You must use each digit argument at least once.

       In  all	cases, the radix character uses is defined by the last successful call to category If category has not been called successfully or
       if the radix character is undefined, the radix character defaults to a period (.).

   International Environment
       LC_NUMERIC     If this environment is set and valid, uses the international language database named in the definition  to  determine  radix
		      character rules.

       LANG	      If  this environment variable is set and valid uses the international language database named in the definition to determine
		      collation and character classification rules.  If is defined, its definition supercedes the definition of LANG.

Examples
       The following example illustrates using an argument to specify field width:
       printf ("%1$d:%2$.*3$d:%4$.*3$d
",
			   hour, min, precision, sec);
       The format string *3$ indicates that the third argument, which is named precision, contains the integer field width specification.

       To print the language independent date and time format use the following statement:
       printf (format, weekday, month, day, hour, min);
       For American use, format could be a pointer to the following string:
       "%1$s,  %2$s %3$d, %4$d:%5$.2d
"
       This string gives the following date format:
       Sunday, July 3, 10:02
       For use in a German environment, format could be a pointer to the following string:
       "%1$s, %3$d. %2$s, %4$d:%5$.2d
"
       This string gives the following date format:
       Sonntag, 3. Juli, 10:02

Return Values
       and return zero for success and EOF for failure.  The subroutine returns its first argument for success and EOF for failure.

       In the System V and POSIX environments, and return the number of characters transmitted for success.  The function ignores the null  termi-
       nator () when calculating the number of characters transmitted.  If an output error occurs, these routines return a negative value.

See Also
       intro(3int), setlocale(3), scanf(3int), printf(3s), putc(3s), scanf(3s), stdio(3s)
       Guide to Developing International Software

																      printf(3int)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy