Sponsored Content
Full Discussion: Simple awk question
Top Forums Shell Programming and Scripting Simple awk question Post 302719075 by Jotne on Monday 22nd of October 2012 04:59:13 AM
Old 10-22-2012
Code:
echo "Happy_world_foo123" | awk -F"foo" '/foo/ {print$2}'

This search for all line with foo and prints all after it.
If you have other characters after number or more than one foo in same line, this does not work.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple awk script question

Hi, I'm a total beginner at awk and hope someone can advise what I have done wrong in the following script: I have a file which (to simplify things) may be something like this Fred Smith and Sue Brown Joe Jones and Jane Watts Sally Green and Jim O? Connor Freda O? Reiley and Pat O?... (2 Replies)
Discussion started by: Bab00shka
2 Replies

2. Shell Programming and Scripting

Simple awk If Satement question.

Trying to write an if statement, which calls2 or 3 functions from within it. code: {if (($34 != "") && (NR != 1) && ($1 != "F")) less_than(34, 0, "S1002a") is_number(34,"S1002a") } But this is only treating the first function call, as part of the if. and always executes is_number.... (1 Reply)
Discussion started by: natdeamer
1 Replies

3. UNIX for Dummies Questions & Answers

simple awk question

Hello, I'm trying to use awk to print lines that match a regular expression. I am using awk to print a record only if it contains N/A. awk '/N/A/ {print $1}' When executed the script returns "awk syntax error near line 1". If I use /N//A/ it prints all records containing a "/", not... (2 Replies)
Discussion started by: orahi001
2 Replies

4. UNIX for Dummies Questions & Answers

simple awk question

Hi , I have a simple question in awk, i have long string which i am getting for a grep command. the output contains 50 fields. I need to display like first 5 fileds in a line and rest of all fields in the next line. { for(i=5;i<NF;++i) s= $i; print $1,$2,$3,$4,$5,"\n",$s} Is the above... (1 Reply)
Discussion started by: senthilkumar_ak
1 Replies

5. Shell Programming and Scripting

simple awk/sed/tr question

I have a file CREATE TABLE DDD_EXT --- 1000 ( val u1 val u1 ); CREATE TABLE dsdasd_EXT --- 1323 ( val u1 val u1 ); CREATE TABLE AAAAAA_EXT --- 1222 ( val u1 val u1 ); CREATE TABLE E_EXT --- 11 ( val u1 val u1 (2 Replies)
Discussion started by: jville
2 Replies

6. Shell Programming and Scripting

simple awk question: split field with :

Hi, Probably a very weak question.. but I have tried all I know.. BPC0001:ANNUL_49542 0.0108 -0.0226 -0.0236 0.0042 0.0033 -0.0545 0.0376 0.0097 -0.0093 -0.032 Control BPC0002:ANNUL_49606 0.0190 -0.0142 -0.0060 -0.0217 -0.0027 ... (3 Replies)
Discussion started by: genehunter
3 Replies

7. UNIX for Dummies Questions & Answers

Simple AWK question

Hi, let's assume i have an output below: orgauser 23826 :E:Validity senerse 2096 senerse 2111 senerse 21585 senerse 21596 root 12653 -bash root 17262 root 17278 Some lines have not any string in their third column. I don't want to see those lines. i just want to see the lines... (3 Replies)
Discussion started by: oduth
3 Replies

8. UNIX for Dummies Questions & Answers

awk simple question

Can anyone tell me please what the "+" is doing in this awk command? find / -user smith -type f -ls | awk '{ sum += $7 } END {print sum }' Thanks, George (2 Replies)
Discussion started by: george_vandelet
2 Replies

9. Shell Programming and Scripting

awk help - Simple question

I have what a think is a simple question but I'm just a beginner in scripting. I'm my unix command line I run a date command that returns the following: Wed Apr 3 10:39:30 EDT 2013 How do I awk out the "10" only in awk? Or is awk the way to do it or is there a better way? (7 Replies)
Discussion started by: scj2012
7 Replies

10. Shell Programming and Scripting

Simple awk question

Here is an awk line I have in a bigger script that checks to see if nimsh process is running and does couple other things based on the output and runs on all servers. ps -ef|grep -i nimsh|awk '{print $9}' and I am expecting output to be "/usr/sbin/nimsh" I find that on some servers... (4 Replies)
Discussion started by: kvosu
4 Replies
Data::Dumper::Simple(3pm)				User Contributed Perl Documentation				 Data::Dumper::Simple(3pm)

NAME
Data::Dumper::Simple - Easily dump variables with names SYNOPSIS
use Data::Dumper::Simple; warn Dumper($scalar, @array, %hash); warn Dumper($scalar, @array, \%hash); warn Dumper $scalar, @array, %hash; ABSTRACT
This module allow the user to dump variables in a Data::Dumper format. Unlike the default behavior of Data::Dumper, the variables are named (instead of $VAR1, $VAR2, etc.) Data::Dumper provides an extended interface that allows the programmer to name the variables, but this interface requires a lot of typing and is prone to tyops (sic). This module fixes that. DESCRIPTION
"Data::Dumper::Simple" is actually a source filter that replaces all instances of "Dumper($some, @args)" in your code with a call to "Data::Dumper->Dump()". You can use the one function provided to make dumping variables for debugging a trivial task. Note that this is primarily a debugging tool. "Data::Dumper" offers a bit more than that, so don't expect this module to be more than it is. Note that if you strongly object to source filters, I've also released Data::Dumper::Names. It does what this module does by it uses Pad- Walker instead of a source filter. Unfortunately, it has a few limitations and is not as powerful as this module. Think of Data::Dumper::Names as a "proof of concept". The Problem Frequently, we use "Data::Dumper" to dump out some variables while debugging. When this happens, we often do this: use Data::Dumper; warn Dumper($foo, $bar, $baz); And we get simple output like: $VAR1 = 3; $VAR2 = 2; $VAR3 = 1; While this is usually what we want, this can be confusing if we forget which variable corresponds to which variable printed. To get around this, there is an extended interface to "Data::Dumper": warn Data::Dumper->Dump( [$foo, $bar, $baz], [qw/*foo *bar *baz/] ); This provides much more useful output. $foo = 3; $bar = 2; $baz = 1; (There's more control over the output than what I've shown.) You can even use this to output more complex data structures: warn Data::Dumper->Dump( [$foo, @array], [qw/*foo *array/] ); And get something like this: $foo = 3; @array = ( 8, 'Ovid' ); Unfortunately, this can involve a lot of annoying typing. warn Data::Dumper->Dump( [$foo, \%this, @array, \%that], [qw/*foo *that *array *this/] ); You'll also notice a typo in the second array ref which can cause great confusion while debugging. The Solution With "Data::Dumper::Simple" you can do this instead: use Data::Dumper::Simple. warn Dumper($scalar, @array, %hash); Note that there's no need to even take a reference to the variables. The output of the above resembles this (sample data, of course): $scalar = 'Ovid'; @array = ( 'Data', 'Dumper', 'Simple', 'Rocks!' ); %hash = ( 'it' => 'does', 'I' => 'hope', 'at' => 'least' ); Taking a reference to an array or hash works as expected, but taking a reference to a scalar is effectively a no-op (because it can turn into a confusing reference to a reference); my $foo = { hash => 'ref' }; my @foo = qw/foo bar baz/; warn Dumper ($foo, @foo); Produces: $foo = { 'hash' => 'ref' }; $foo = [ 'foo', 'bar', 'baz' ]; Note that this means similarly named variables can get quite confusing, as in the example above. If you already have a &Dumper function, you can specify a different function name with the "as" key in the import list: use Data::Dumper::Simple as => 'display'; warn display( $scalar, @array, %hash ); Also, if you really, really can't stand typing "warn" or "print", you can turn on "autowarn": use Data::Dumper::Simple as => 'display', autowarn => 1; display($scalar, @array, $some->{ data }); Or you can send the output (as a list) to a different function: use Data::Dumper::Simple as => 'debug', autowarn => 'to_log'; sub to_log { my @data = @_; # some logging function } debug( $customer => @order_nums ); # yeah, we support the fat comma "=>" and newlines EXPORT
The only thing exported is the Dumper() function. Well, actually that's not really true. Nothing is exported. However, a source filter is used to automatically rewrite any apparent calls to "Dumper()" so that it just Does The Right Thing. SEE ALSO
* Data::Dumper - Stringified perl data structures * Filter::Simple - Simplified source filtering BUGS
This module uses a source filter. If you don't like that, don't use this. There are no known bugs but there probably are some as this is Alpha Code. LIMITATIONS
* Calling with a sub Do not try to call "Dumper()" with a subroutine in the argument list: Dumper($foo, some_sub()); # Bad! The filter gets confused by the parentheses. Your author was going to fix this but it became apparent that there was no way that "Dumper()" could figure out how to name the return values from the subroutines, thus ensuring further breakage. So don't do that. * Multiple enreferencing Getting really crazy by using multiple enreferencing will confuse things (e.g., "\\\$foo"), don't do that, either. I might use "Text::Balanced" at some point to fix this if it's an issue. * Slices List and hash slices are not supported at this time. * String interpolation "Dumper($foo)" can potentially interpolate if it's in a string. This is because of a weird edge case with "FILTER_ONLY code" which caused a failure on some items being dumped. I've fixed that, but made the module a wee bit less robust. This will hopefully be fixed in the next release of Text::Balanced. * Line numbers may be wrong Because this module uses a source filter, line numbers reported from syntax or other errors may be thrown off a little. This is probably a bug in the source filter implementation, which should use "#line" directives. As a workaround until this is fixed, put a directive (such as "#line 10000") a few lines ahead of the suspected bug. If the error is reported as happening in line 10007, you know to look about eight lines below your directive for the bug. Be sure to remove the bogus directive once you find the bug! * The parentheses are optional, but the syntax isn't bulletproof If you try, it's not hard to confuse the parser. Patches welcome. Note that this is not a drop-in replacement for "Data::Dumper". If you need the power of that module, use it. AUTHOR
Curtis "Ovid" Poe, <eop_divo_sitruc@yahoo.com> Reverse the name to email me. COPYRIGHT AND LICENSE
Copyright 2004 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-03-08 Data::Dumper::Simple(3pm)
All times are GMT -4. The time now is 02:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy