Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. futurelet

    Problems with FS " "

    If every field is surrounded by quotes, then try this: FS = "\",\"" For every line, you'll need this: gsub( /^"|"$/, "" )
  2. futurelet

    print selected lines

    awk -v target=$lines 'NR == target' file1 >> file2
  3. futurelet

    smart program!!

    { for (i=2; i<=NF; i++) s[i] += $i } END { for (i=2; i in s; i++) { printf "%s%f", x, s[i] x = " " } }
  4. futurelet

    Parsing file and adding like fields

    I'm glad you were able to fix it. Another approach would be to make sure that every client has a ".". server = substr($2,1,index($2 ".", ".")-1)
  5. futurelet

    Parsing file and adding like fields

    Can you give a more detailed description of the problem? Or show some input data from which the program generates bad output?
  6. futurelet

    Parsing file and adding like fields

    This should get you started. BEGIN { FS = ": +" } "Client" == $1 { server = substr($2,1,index($2,".")-1) keys[ server ]++ } "Policy" == $1 { data[ server, "policy" ] = $2 } "Backup Time" == $1 { data[ server, "time" ] = $2 } "Elapsed Time" == $1 { data[ server,"elapsed"] += secs($2) }...
  7. futurelet

    Manipulate files

    I shortened Feherke's code: awk 'ORS=NF>4?FS:RS' myfile
  8. futurelet

    gawk for windows error

    Putting a program on the command-line is usually harder in windows than under unix. This should work. gawk "length($0)<100{$0=sprintf(\"%-100s\",$0)}1" input_file If you have mawk, try mawk "length($0)<100{$0=sprintf('%-100s',$0)}1" input_file Another way to feed a program to awk: echo...
  9. futurelet

    Convert fields 4 &amp; 5 to GB/TB

    Under Solaris, use /usr/xpg4/bin/awk. This will preserve the spacing between columns. Put in file "convertfields.awk" and run with /usr/xpg4/bin/awk -f convertfields.awk /foo # Produces array of nonmatching and matching # substrings. The size of the array will # always be an odd number. The...
  10. futurelet

    need help getting system date using AWK pgm.

    I got the impression the o.p. was running under windoze, where the user has to press <Enter> after running "date". Maybe he can clarify this.
  11. futurelet

    need help getting system date using AWK pgm.

    system( "echo.|date" )
  12. futurelet

    delete all lines between two patterns

    awk '/BEGIN/,/END/{next}1' file works with awk, gawk, and mawk (I just tested it). You're probably using something antique and obsolete. If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk. And of...
  13. futurelet

    delete all lines between two patterns

    awk '/BEGIN/,/END/{next}1'
  14. futurelet

    Return field number of string in a line

    Glad you liked it. [thumbsup2]
  15. futurelet

    Return field number of string in a line

    BEGIN { target = "KnownString" } /^\+/ { sub( /^\+/, "" ); line = line $0 ; next } { process( line ) line = $0 } END { process( line ) } function process( line ) { split( line, ary, /[ \t]+/ ) for (i=1; i in ary; i++) { if (target == ary[i]) print ary[i+1] } }
  16. futurelet

    how to pass parameters into regular expression, i.e., /parameter/

    FILENAME == ARGV[1] { if ( $1 != "" ) keys[ toupper($1) ] = $0 next } { for (key in keys) { if ( index( toupper($1), key ) ) print keys[key], $0 } } Is this better?
  17. futurelet

    how to pass parameters into regular expression, i.e., /parameter/

    FILENAME == ARGV[1] { keys[ toupper($1) ] = $0 next } { for (key in keys) { if ( index( toupper($1), key ) ) print keys[key], $0 } }
  18. futurelet

    how to pass parameters into regular expression, i.e., /parameter/

    Using ~ is one way to see if a reg.ex. matches a string. BEGIN{ print "foo bar" ~ /o.b/ } If you have an explicit reg.ex. like /.../, matching against $0 is automatic: BEGIN{ $0 = "foo bar"; print /o.b/ } But if the reg.ex. is disguised as a string, we have to let awk know that we want it...
  19. futurelet

    how to pass parameters into regular expression, i.e., /parameter/

    awk 'NR==FNR{$1=$1;r=$0;next}$0 ~ r' OFS='|' file1 file2
  20. futurelet

    how to pass parameters into regular expression, i.e., /parameter/

    Here's a more understandable version. # Are we reading 1st file? FILENAME==ARGV[1] { #Convert whitespace in $0 to "|". gsub( /[ \t]+/, "|" ) # Save our regular expression. r = $0 # Read next line. next } # Print line if it matches the string that # is being used as a regular...

Part and Inventory Search

Back
Top