Sponsored Content
Top Forums Shell Programming and Scripting awk output to multiple variables Post 302672505 by Corona688 on Monday 16th of July 2012 12:18:40 PM
Old 07-16-2012
First problem, all your data is separated by white space so you'll get two things, not four. Easily solved though:

Code:
$ awk -F, -v ORS="," '{print $2, $3}' data

USA loc2,GB loc4,

$

Now it's just a matter of letting the shell do splitting on ",".

Code:
$ OLDIFS="$IFS"
$ IFS=","
$ set --  $(awk -F, -v ORS="," '{print $2, $3}' data)
$ IFS="$OLDIFS"
$ echo $1

USA loc2

$ echo $2

GB loc4

$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing awk output into variables

Hi all, Currently, i have a log file seperated by 'tab' and each record starting with a new line. i managed to retrieve the column that i'm interested in. (source_ip_address: xxx.xxx.xxx.xxx). example of awk output: '{ print $43 }' assuming the field is at column 43. 10.10.10.10... (4 Replies)
Discussion started by: faelric
4 Replies

2. Shell Programming and Scripting

sql output from multiple rows and columns as variables in a script

This is for an Oracle journal import. I was using a pl/sql package and oracle API's. Oracle added invoker rights to their API's and now my package won't run. I didn't want to use their API's anyway. The only reason i was using pl/sql and the API's (just a package) was to utilize a cursor. How... (2 Replies)
Discussion started by: lmu
2 Replies

3. Shell Programming and Scripting

awk output to variables

Im trying to read the awk output to two variables. In the below code i need to store the if part output to a variable (NEW) and else part output to another variable (BAD). Pls shed some light on this snippet or if there is any other way to achieve it wud be appreciated (only condition is it needs... (7 Replies)
Discussion started by: michaelrozar17
7 Replies

4. Shell Programming and Scripting

awk (or other) script that assigns fields from a line to multiple variables

Hey all, Unfortunately I have only basic knowledge of awk and/or scripting. If I have a file with lines that can look similar to this: Name=line1 Arg1=valueA Arg2=valueB Arg3=valueC Name=line2 Arg1=valueD Name=line3 Arg1=valueE Arg3=valueF Name=line4 Arg2=valueG ... (4 Replies)
Discussion started by: Rike255
4 Replies

5. Shell Programming and Scripting

Variables into SED or AWK and multiple commands

Hello I am hoping you may help. I am not sure how to go about this exactly, I know the tools but not sure how to make them work together. I have two SED commands that I would like to run in a shell script. I would like to take the manual input of a user (types in when prompted) to be used... (4 Replies)
Discussion started by: lostincashe
4 Replies

6. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

7. Shell Programming and Scripting

How to redirect the output of awk to different variables?

Hi, I search for a string "can be any" and print the fields $4,$6 in to variables. $ cat input <value ='can be any' string='many' version='123'/> <value ='xyz' string='less' version='456'/> $ cat tried_code SRG=`awk -F\' '{ print $4 }' input` VER=`awk -F\' '{ print $6 }' input` ... (4 Replies)
Discussion started by: greet_sed
4 Replies

8. Shell Programming and Scripting

Format output into columns, variables with multiple entries

Hello all, I've got a script that collects data on file systems and prints out specific data about each. I've formatted headers w/ printf like so. printf "\033 and I had the content of the varibles printed out beneath those columns like so: printf... (5 Replies)
Discussion started by: awreneau
5 Replies

9. UNIX for Advanced & Expert Users

awk With multiple print variables

Hi, I have a parameter which will be having the fields which needs to be filtered or derived. But This is not working which is mentioned below. I am using the below mentioned OS uname -a SunOS udora310 5.10 Generic_150400-11 sun4v sparc sun4v param='$1$2' nawk -v para="$param" 'BEGIN... (11 Replies)
Discussion started by: Mohammed Rafi
11 Replies

10. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies
Perl6::Say(3pm) 					User Contributed Perl Documentation					   Perl6::Say(3pm)

NAME
Perl6::Say - "print" -- but no newline needed SYNOPSIS
# Perl 5 code... use Perl6::Say; say 'boo'; # same as: print 'boo', " " say STDERR 'boo'; # same as: print STDERR 'boo', " " STDERR->say('boo'); # same as: print STDERR 'boo', " $fh->say('boo'); # same as: print $fh 'boo', " "; say(); # same as: print "$_ "; say undef; # same as: print " "; DESCRIPTION
Note for Users of Perl 5.10 You don't need this module. The Perl 6 "say" function is available in Perl 5.10 by saying "use feature 'say';". Hence, this module is of interest only to users of Perl 5.6 and 5.8. If you have Perl 5.10 installed, see the 510/ directory in this distribution for some elementary examples of "say" taken from "perldoc fea- ture". General Implements a close simulation of the "say" function in Perl 6, which acts like "print" but automatically appends a newline. Use it just like "print" (except that it only supports the indirect object syntax when the stream is a bareword). That is, assuming the relevant filehandles are open for output, you can use any of these: say @data; say FH @data; FH->say(@data); *FH->say(@data); (*FH)->say(@data); say $fh, @data; $fh->say(@data); but not any of these: say {FH} @data; say {*FH} @data; say {*FH} @data; say $fh @data; say {$fh} @data; Additional Permitted Usages As demonstrated in the test suite accompanying this distribution, "Perl6::Say::say()" can be used in all the following situations. $string = q{}; open FH, ">", $string; say FH qq{Hello World}; # print to a string close FH; # requires Perl 5.8.0 or later use FileHandle; $fh = FileHandle->new($file, 'w'); if (defined $fh) { say $fh, qq{Hello World}; $fh->close; } use IO::File; $fh = IO::File->new($file, 'w'); if (defined $fh) { say $fh, qq{Hello World}; $fh->close; } $string = q{}; open FH, ">", $string; # requires Perl 5.8.0 or later select(FH); say qq{Hello World}; close FH; Interaction with Output Record Separator In Perl 6, "say @stuff" is exactly equivalent to "Core::print @stuff, " "". That means that a call to "say" appends any output record separator (ORS) after the added newline (though in Perl 6, the ORS is an attribute of the filehandle being used, rather than a global $/ variable). "IO::Handle::say()" IO::Handle version 1.27 or later (which, confusingly, is found in IO distribution 1.23 and later) also implements a "say" method. Perl6::Say provides its own "say" method to IO::Handle if "IO::Handle::say" is not available. Usage with Older Perls As noted above, some aspects of "Perl6::Say::say()" will not work with versions of Perl earlier than 5.8.0. This is not due to any problem with this module; it is simply that Perl did not support printing to an in-memory file ("print $string, " ";") prior to that point. (Thanks to a CPAN testers report from David Cantrell for identifying this limitation.) WARNING
The syntax and semantics of Perl 6 is still being finalized and consequently is at any time subject to change. That means the same caveat applies to this module. DEPENDENCIES
No dependencies other than on modules included with the Perl core as of version 5.8.0. Some of the files in the test suite accompanying this distribution use non-core CPAN module IO::Capture::Stdout. Tests calling IO::Cap- ture::Stdout methods are enclosed in "SKIP" blocks and so should pose no obstacle to installation of the distribution on systems lacking IO::Capture. (However, the maintainer strongly recommends IO::Capture for developers who write a lot of test code. So please consider installing it!) AUTHOR and MAINTAINER AUTHOR Damian Conway (damian@conway.org). MAINTAINER James E Keenan (jkeenan@cpan.org) (effective v0.06, July 2006). ACKNOWLEDGMENTS
Thanks to Damian Conway for dreaming this up. Thanks to David A Golden for a close review of the documentation. Thanks to CPAN tester Jost Krieger for reporting an error in my SKIP block count in one test file. BUGS AND IRRITATIONS
As far as we can determine, Perl 5 doesn't allow us to create a subroutine that truly acts like "print". That is, one that can simultane- ously be used like so: say @data; and like so: say {$fh} @data; Comments, suggestions, and patches welcome. COPYRIGHT
Copyright (c) 2004, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. perl v5.8.8 2008-02-09 Perl6::Say(3pm)
All times are GMT -4. The time now is 04:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy