Sponsored Content
Full Discussion: cat arguments to a function
Top Forums Shell Programming and Scripting cat arguments to a function Post 302443740 by Random_Net on Tuesday 10th of August 2010 02:50:51 AM
Old 08-10-2010
Question cat arguments to a function

Hi,

I've a logging function in bourne shell, flog() which logs the first argument passed to it. How can I pass arguments to this function from a file, like

Code:
cat filename | sed '...filtering...' | flog

or
Code:
cat filename | sed '...filtering...' | xargs flog

Which did not work, after which then I tried to use a while loop to feed the lines one by one to the function :

Code:
while read line
do
   flog "$line"
done < `cat filename | sed '...filtering...'  `

However the above method also did not work.

Finally I was able to do it by first creating the filtered file, then parsing it through the loop:

Code:
cat filename | sed '...filtering...'  > filename2 
while read line
do
   flog "$line"
done < filename2

Is there a more elegant way of doing this?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

count no of arguments passed to a function

hi i have a function abc { //from this function i am passing args to antoher function like def a b c j k l } now i want to count the no of args coming to def() function and iterate over those values is there any way to do this one please help (2 Replies)
Discussion started by: satish@123
2 Replies

2. Shell Programming and Scripting

Passing arguments to Perl Function

Hi All, I am trying to pass an argument called "Pricelist" to a Perl function, then the function will open and print out the contents of the file named "Pricelist". But i can't seem to do it using my below code. Can any expert give some advice? #!/usr/local/bin/perl $DATABASE =... (1 Reply)
Discussion started by: Raynon
1 Replies

3. Programming

Error: too many arguments to function 'sigwait'

#include <pthread.h> #include <signal.h> ... sigset_t mask; int err,signo; err=sigwait(&mask,&signo); switch(signo){ case SIGINT: ... } when I compile above code under solaris 10,it raise following error: error: too many arguments to function 'sigwait' I look up signal... (4 Replies)
Discussion started by: konvalo
4 Replies

4. UNIX for Advanced & Expert Users

Function not called when no arguments is passed

Hi Guys, I am trying to pass arguments to the script i am wrinting. When no argument is passed or wrong argument is passed, the script needs to output the way it needs to be called and exit. Currently, when no arguments is passed, it is not getting exited but goes on assuming those... (3 Replies)
Discussion started by: mac4rfree
3 Replies

5. Shell Programming and Scripting

bash read within function with arguments

I have trouble getting this logic to work #!/bin/bash function assign_var(){ while do read -p "$2 :" $3 done } assign_var '$IPADDRESS' ipaddress IPADDRESS Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle... (11 Replies)
Discussion started by: serverchief
11 Replies

6. UNIX for Dummies Questions & Answers

How to modify the script to include cat function

I have the following script that greps lines containing "AT" from data files data1.hsq through data1000.hsq, then cuts their second column and puts in data files called perm1 through perm1000. I want to modify the script so that instead of putting the data in separate data files perm1 through... (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Need to call a function with arguments

I need to call a function within a code with $database and $ service as the arguments How do I proceed ? and how would a function be defined and these two arguments would be used inside the function? calc_pref_avail $database $service Best regards, Vishal (7 Replies)
Discussion started by: Vishal_dba
7 Replies

8. Shell Programming and Scripting

Cat a script, pipe it, then pass arguments to it?

suppose i have a perl script that is normally run this way: ./checkdisk.pl -H hostname -w 40 -c 80 but, for whatever reason, i cannot run the script directly as it should. But i can cat it through pipe. How can i pass the arguments "-H hostname -w 40 -c 80"? so this is what i'm doing,... (6 Replies)
Discussion started by: SkySmart
6 Replies

9. Shell Programming and Scripting

Bash function failing with [: too many arguments

I'm reading Wicked Cool Shell Scripts. For some reason, the function pasted in below gives the error: ./inpath2: line 10: in_path() 4 { 5 cmd=$1 ourpath=$2 result=1 6 oldIFS=$IFS IFS=":" 7 8 for directory in "$ourpath" 9 do 10 if ; then 11 result=0 12 fi... (9 Replies)
Discussion started by: jakeroberts
9 Replies

10. Shell Programming and Scripting

Call same function using 2 different arguments

I have a script that uses 2 arguments. I want to call the function part within this script using these same arguments. Below is what I came up with below script so far, any guidance would be helpful. Thank you! cat backup.sh #!/bin/bash function usage { echo "USAGE: $(basename $0)... (6 Replies)
Discussion started by: mbak
6 Replies
String::Flogger(3pm)					User Contributed Perl Documentation				      String::Flogger(3pm)

NAME
String::Flogger - string munging for loggers VERSION
version 1.101242 SYNOPSIS
use String::Flogger qw(flog); my @inputs = ( 'simple!', [ 'slightly %s complex', 'more' ], [ 'and inline some data: %s', { look => 'data!' } ], [ 'and we can defer evaluation of %s if we want', sub { 'stuff' } ], sub { 'while avoiding sprintfiness, if needed' }, ); say flog($_) for @inputs; The above will output: simple! slightly more complex and inline some data: {{{ "look": "data!" }}} and we can defer evaluation of stuff if we want while avoiding sprintfiness, if needed METHODS
flog This method is described in the synopsis. format_string $flogger->format_string($fmt, @input); This method is used to take the formatted arguments for a format string (when "flog" is passed an arrayref) and turn it into a string. By default, it just uses ""sprintf" in perlfunc". AUTHOR
Ricardo SIGNES <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo SIGNES <rjbs@cpan.org>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-03-26 String::Flogger(3pm)
All times are GMT -4. The time now is 03:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy