Sponsored Content
Full Discussion: awk to perform splitting
Top Forums Shell Programming and Scripting awk to perform splitting Post 302951020 by MadeInGermany on Friday 31st of July 2015 10:58:33 AM
Old 07-31-2015
Instead of appending each output with >> (which denotes open,seek,write,close each time), you can redirect the entire loop
Code:
for i in a b c
 do
 echo "$i"
done > outfile

The shell opens the file when the loop starts and closes it when the loop ends.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a string with awk

Hi all, I want to split a string in awk and treat each component seperatley. I know i can use: split ("hi all", a, " ") to put each delimited component into array a. However when i want to do this with just a string of chars it does not work split ("hi", a, ""); print a; prints... (6 Replies)
Discussion started by: pxy2d1
6 Replies

2. UNIX for Dummies Questions & Answers

Record splitting with AWK

Hi all ! I need your help as quick as possible. My input file like this: bạc těnh ( 薄情) 1 . 薄情な.2. 夫婦或いは男女の不貞を指す。 bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)・ 3.圧迫する.4.差し迫った, My propose is take the value in the firt bracket. I used the command like : ...if (index(... (6 Replies)
Discussion started by: maixu134
6 Replies

3. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

4. Shell Programming and Scripting

perform echo and awk inside a string

hi, just wanted to make a shortcut of this one a="a b c" b=`echo $a | awk '{print $2}'` echo "the middle is $b" why can't i do this: a="a b c" echo "the middle is ${`echo $a | awk '{print $2}'`}" <- bad substitution :wall: thanks (6 Replies)
Discussion started by: h0ujun
6 Replies

5. Shell Programming and Scripting

How To Perform Mathematical Operation Within If in awk?

Hi All, I am using an awk script as below: awk -F'|' 'BEGIN{OFS="|";} { if ($1==$3 && $3==$7 && $7==$13 && $2==$6 && $6==$11 && $15-$14+1==$11) print $0"|""TRUE"; else print $0"|""FALSE"; }' tempfile.txt In above script, all conditions are being checked except the one which is... (4 Replies)
Discussion started by: angshuman
4 Replies

6. Shell Programming and Scripting

How to perform averaging of values for particular timestamp using awk or anythoing else??

I have a file of the form. 16:00:26,83.33 16:05:26,83.33 16:10:26,83.33 16:15:26,83.33 16:20:26,90.26 16:25:26,83.33 16:30:26,83.33 17:00:26,83.33 17:05:26,83.33 17:10:26,83.33 17:15:26,83.33 17:20:26,90.26 17:25:26,83.33 17:30:26,83.33 For the timestamp 16:00:00 to 16:55:00, I need to... (5 Replies)
Discussion started by: Saidul
5 Replies

7. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies

8. Shell Programming and Scripting

Why awk perform differently when using variable?

Hi Gurus, I hit a hard block in my script. when using awk command with variable, I got different result. Please see below: my test file as below: $ cat demofile.txt filename-yyyy-abcd filename-xxx-week-pass filename-xxx-week-run for testing purpose, I put 3 awk command in one script.... (7 Replies)
Discussion started by: ken6503
7 Replies

9. Shell Programming and Scripting

awk script to find data in three file and perform replace operation

Have three files. Any other approach with regards to file concatenation or splitting, etc is appreciated If column55(billngtype) of file1 contains YMNC or YPBC then pick the value of column13(documentnumber). Now find this documentnumber in column1(Billdoc) of file2 and grep the corresponding... (4 Replies)
Discussion started by: as7951
4 Replies

10. Shell Programming and Scripting

awk script concatenate two column and perform mutiplication

Need your help in solving this puzzle. Any kind of help will be appreciated and link for any documents to read and learn and to deal with such scenarios would be helpful Concatenate column1 and column2 of file 1. Then check for the concatenated value in Column1 of File2. If found extract the... (14 Replies)
Discussion started by: as7951
14 Replies
IO::Async::Socket(3pm)					User Contributed Perl Documentation				    IO::Async::Socket(3pm)

NAME
"IO::Async::Socket" - event callbacks and send buffering for a socket filehandle SYNOPSIS
use IO::Async::Socket; use IO::Async::Loop; my $loop = IO::Async::Loop->new; $loop->connect( host => "some.host.here", service => "echo", socktype => 'dgram', on_connected => sub { my ( $sock ) = @_; my $socket = IO::Async::Socket->new( handle => $sock, on_recv => sub { my ( $self, $dgram, $addr ) = @_; print "Received reply: $dgram ", $loop->stop; }, on_recv_error => sub { my ( $self, $errno ) = @_; die "Cannot recv - $errno "; }, ); $loop->add( $socket ); $socket->send( "A TEST DATAGRAM" ); }, on_resolve_error => sub { die "Cannot resolve - $_[0] "; }, on_connect_error => sub { die "Cannot connect "; }, ); $loop->run; DESCRIPTION
This subclass of IO::Async::Handle contains a socket filehandle. It provides a queue of outgoing data. It invokes the "on_recv" handler when new data is received from the filehandle. Data may be sent to the filehandle by calling the "send" method. It is primarily intended for "SOCK_data" or "SOCK_RAW" sockets; for "SOCK_STREAM" sockets an instance of IO::Async::Stream is probably more appropriate. EVENTS
The following events are invoked, either using subclass methods or CODE references in parameters: on_recv $data, $addr Invoke on receipt of a packet, datagram, or stream segment. The "on_recv" handler is invoked once for each packet, datagram, or stream segment that is received. It is passed the data itself, and the sender's address. on_recv_error $errno Optional. Invoked when the "recv" method on the receiving handle fails. on_send_error $errno Optional. Invoked when the "send" method on the sending handle fails. The "on_recv_error" and "on_send_error" handlers are passed the value of $! at the time the error occured. (The $! variable itself, by its nature, may have changed from the original error by the time this handler runs so it should always use the value passed in). If an error occurs when the corresponding error callback is not supplied, and there is not a subclass method for it, then the "close" method is called instead. on_outgoing_empty Optional. Invoked when the sending data buffer becomes empty. PARAMETERS
The following named parameters may be passed to "new" or "configure": read_handle => IO The IO handle to receive from. Must implement "fileno" and "recv" methods. write_handle => IO The IO handle to send to. Must implement "fileno" and "send" methods. handle => IO Shortcut to specifying the same IO handle for both of the above. on_recv => CODE on_recv_error => CODE on_outgoing_empty => CODE on_send_error => CODE autoflush => BOOL Optional. If true, the "send" method will atempt to send data to the operating system immediately, without waiting for the loop to indicate the filehandle is write-ready. recv_len => INT Optional. Sets the buffer size for "recv" calls. Defaults to 64 KiB. recv_all => BOOL Optional. If true, repeatedly call "recv" when the receiving handle first becomes read-ready. By default this is turned off, meaning at most one fixed-size buffer is received. If there is still more data in the kernel's buffer, the handle will stil be readable, and will be received from again. This behaviour allows multiple streams and sockets to be multiplexed simultaneously, meaning that a large bulk transfer on one cannot starve other filehandles of processing time. Turning this option on may improve bulk data transfer rate, at the risk of delaying or stalling processing on other filehandles. send_all => INT Optional. Analogous to the "recv_all" option, but for sending. When "autoflush" is enabled, this option only affects deferred sending if the initial attempt failed. The condition requiring an "on_recv" handler is checked at the time the object is added to a Loop; it is allowed to create a "IO::Async::Socket" object with a read handle but without a "on_recv" handler, provided that one is later given using "configure" before the stream is added to its containing Loop, either directly or by being a child of another Notifier already in a Loop, or added to one. METHODS
$socket->send( $data, $flags, $addr ) This method adds a segment of data to be sent, or sends it immediately, according to the "autoflush" parameter. $flags and $addr are optional. If the "autoflush" option is set, this method will try immediately to send the data to the underlying filehandle, optionally using the given flags and destination address. If this completes successfully then it will have been sent by the time this method returns. If it fails to send, then the data is queued as if "autoflush" were not set, and will be flushed as normal. SEE ALSO
o IO::Handle - Supply object methods for I/O handles AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Socket(3pm)
All times are GMT -4. The time now is 01:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy