Sponsored Content
Top Forums UNIX for Advanced & Expert Users awk With multiple print variables Post 302941164 by vgersh99 on Monday 13th of April 2015 01:20:20 PM
Old 04-13-2015
Quote:
Originally Posted by Mohammed Rafi
Many thanks, This is working perfectly fine.

nawk -v para="$param" 'BEGIN {FS="\037";OFS="\037"; n=split (para, P, "$")} {for(i=2; i<=n;i++) printf("%s%s", $P[i], (i==n)?ORS:OFS)}' 1.dat

Regards,

---------- Post updated at 12:03 PM ---------- Previous update was at 12:02 PM ----------

Just not sure why the first number i should be equal to 2?, But it works
If your param='$1$2' and you n=split (para, P, "$"), then the P[1] is empty as the field preceding the FIRST $, is empty.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

print multiple lines with awk

Hi everyone! I'm not new to Unix, but I've never used awk before. I tried to look up this information on several sites and forums, I also looked in the documentation but I haven't found a solution yet. I would like to print the previous 3 lines before and the following 4 lines after the... (6 Replies)
Discussion started by: djcsabus
6 Replies

2. 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

3. Shell Programming and Scripting

print pattern between two variables awk sed

I am trying to print text between two variables in a file I have tried the following things but none seem to work: awk ' /'$a'/ {flag=1;next} /'$b'/{flag=0} flag { print }' file and also sed "/$a/,/$b/p" file But none seem to work Any Ideas? Thanks in Advance (5 Replies)
Discussion started by: forumbaba
5 Replies

4. Shell Programming and Scripting

To print variables using awk

Can anyone help me with how to print the variable using a awk statement. for i in ` cat serverlist.txt ` ; do my command | awk '{print $1 $2 $i}' done It should print like below but it is not XXXXX YYYYY Servername XXXXX YYYYY Servername XXXXX YYYYY Servername XXXXX YYYYY... (6 Replies)
Discussion started by: rrb2009
6 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

awk output to multiple variables

Hi I need to assign the ouput of a awk statement to two variables; below is a example of the txt file i have which I use awk against sample file testval,USA,loc2,testing02 testval1,GB,loc4,testing01 awk statement awk -F , '{print $2,$3}' USA loc2 GB loc4 I need a method where... (6 Replies)
Discussion started by: duckeggs01
6 Replies

7. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

8. 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

9. Shell Programming and Scripting

Awk: is it possible to print into multiple columns?

Hi guys, I have hundreds file like this, here I only show two of them: file 1 feco4_s_BB95.log ZE_1=-1717.5206260 feco4_t_BB95.log ZE_1=-1717.5169250 feco5_s_BB95.log ZE_1=-1830.9322060... (11 Replies)
Discussion started by: liuzhencc
11 Replies

10. Shell Programming and Scripting

Multiple variables using awk and for loop for web form submission

Hi My goal is to fill an HTML form and submit. What I have managed to do: 1. curl command to fill up the form and submit 2. a file which has the input curl command: curl -v -b cookie.txt -d __CSRFToken__=dc23d5da47953b3b390ec68d972af10380908b14 -d do=create -d a=open -d... (10 Replies)
Discussion started by: zorrox
10 Replies
FBB::OFilterStreambuf(3bobcat)					 ostream filtering				    FBB::OFilterStreambuf(3bobcat)

NAME
FBB::OFilterStreambuf - Base class for std::ostream filtering SYNOPSIS
#include <bobcat/ofilterstreambuf> Linking option: -lbobcat DESCRIPTION
The FBB::OFilterStreambuf class is a specialization of the std::streambuf class and can be used as a base class for classes implementing ostream-filtering. Ostream filtering is defined here as the process by which inserted characters are subject to processing before they are passed on to another (filtered) ostream object (or they may be rejected). The filtering may also result in inserting additional information into the filtered ostream. Chaining of filters is also possible: the filtered ostream may itself use an OFilterStreambuf to filter its received information before passing it on to yet another ostream. As OFilterStreambuf inherits from std::streambuf an OFilterStreambuf object can be used to provide an ostream object with a std::streambuf. Information inserted into such a stream travels the following route: o The information is converted to characters using the standard conversion facilities implemented by std::ostream objects. E.g., when inserting the value 123 this value is converted to the characters '1', '2' and '3', respectively. o Each of the characters is then offered (in turn) to the std::streambuf that is associated with the ostream object. In particular, the std::streambuf's overflow() member is called. o OFstreamBuf's default overflow() function ignores characters, but specializations can override overflow() to process the received characters ad lib. o A overriding overflow() function has access to the member OFstreambuf::out() which is a reference to the std::ostream receiving the filtered information. To implement a simple copy-filter (i.e., all characters are accepted as-is) a class must be derived from OFilterStreambuf providing an overriding implementation of overflow(), e.g., as follows: int DerivedClass::overflow(int ch) { out().put(ch); } Next this std::streambuf specialization can be associated with an ostream into which information to be `copy filtered' can be inserted (cf. the EXAMPLE section below). NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::streambuf CONSTRUCTORS
o OFilterStreambuf(): This constructor creates a OFilterStreambuf object without associating it with a destination (filtered) ostream. o OFilterStreambuf(char const *fname, openmode mode = std::ios::out): This constructor creates a OFilterStreambuf object and opens a private std::ofstream object whose filename is provided and that should receive the filtered information. o OFilterStreambuf(std::ostream &out): This constructor creates a OFilterStreambuf object and will insert any filtered information into the provided ostream object. The class's destructor closes the destination (filtered) stream (cf. the description of close() below). MEMBER FUNCTIONS
All members of std::ostreambuf are available, as FBB::OFilterStreambuf inherits from that class. In particular, derived classes should pro- vide their own implementation of int underflow(int ch) to implement any non-trivial filtering. o void close(): This member calls the streambuf::sync() member to flush any pending information to the destination (filtered) stream and then closes the destination stream. Note that the default sync() member performs no special actions but it can be overridden by derived classes to flush the destination stream just prior to its closing. o void open(char const *fname, openmode mode = std::ios::out): This member closes the current destination (filtered) std::ostream object and associates the OFilterStreambuf object with a private std::ofstream object whose filename is provided and that should receive subsequently filtered information. o void open(std::ostream &out): This member closes the current destination (filtered) std::ostream object and associates the OFilterStreambuf object with the pro- vided ostream object. PROTECTED MEMBER FUNCTION
o std::ostream &out() const: This member is available to derived classes to insert information into the destination (filtered) stream. EXAMPLE
#include <iostream> #include <cctype> #include <bobcat/ofilterstreambuf> class NoDigits: public FBB::OFilterStreambuf { public: int overflow(int ch) { if (not isdigit(ch)) out().put(ch); return ch; } int sync() { out() << flush; return 0; } }; using namespace FBB; using namespace std; int main() { NoDigits nod(cout); // no digits to cout ostream out(&nod); out << in.rdbuf(); // rm digits from cin return 0; } FILES
bobcat/ofilterstreambuf - defines the class interface SEE ALSO
bobcat(7) BUGS
None Reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::OFilterStreambuf(3bobcat)
All times are GMT -4. The time now is 04:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy