Sponsored Content
Top Forums Shell Programming and Scripting any savant ? using AWK/SED to remove newline character between two strings : conditional removal Post 302501184 by sieger007 on Wednesday 2nd of March 2011 10:46:23 PM
Old 03-02-2011
Question

That was very helpful except for the fact that it does not 'think' like this .
What I am trying to do is getting rid of the newline characters - that erroneously break the word and make things incoherent.
LOGIC:


-- Go Find a String1
---Look for the nth instance of String1
-- From the nth instance onwards , excluding string1 : `do this stuff`
-- Keep doing till you come to the 'm th' instance of string 2 , excluding String2.
The above was a brilliant idea , except for the fact that I cannot gurantee that there is a paragraph in every file , that can be used as line separator
So your looking at something like this :



Code:
Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
Begin Transaction ;
The shells sh
e sells a
re sea-sh
ells, I'm s
ure.
replace function ()
Blah

Output should be :

Code:
Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
Begin Transaction ;
The shells she sells are sea-shells, I'm sure.
replace function ()
Blah

.The above AWK gives this o/p

Code:
Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
/* there is no newline char after the begin transaction below. It shd be there * /
Begin Transaction ;The shells she sells are sea-shells, I'm sure.
replace function ()
Blah

THANKS for your help
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies

2. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

3. Shell Programming and Scripting

sed help with character removal

Hello I've got a string of text with a number in pence, e.g. 0.52p, I need to remove the 'p' so that it just reads 0.52 without of course removing all the other 'p' characters. Many thanks (1 Reply)
Discussion started by: mrpugster
1 Replies

4. Shell Programming and Scripting

Remove newline character between two delimiters

hi i am having delimited .dat file having content like below. test.dat(5 line of records) ====== PT2~Stag~Pt2 Stag Test. Updated~PT2 S T~Area~~UNCEF R20~~2012-05-24 ~2014-05-24~~ PT2~Stag y~Pt2 Stag Test. Updated~PT2 S T~Area~METR~~~2012-05-24~2014-05-24~~test PT2~Pt2 Stag Test~~PT2 S... (4 Replies)
Discussion started by: sushine11
4 Replies

5. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

6. Shell Programming and Scripting

Want to remove / and character using awk or sed

Below i am trying to remove "/" and "r" from the output, so i need output as: hdiskpower3 hdisk0 hdisk1 #inq | grep 5773 | awk '{print $1}' | sed 's/dev//g' | awk -F"/" '{$1=$1}1' .....................................................//rhdiskpower0 //rhdiskpower1 //rhdiskpower2... (3 Replies)
Discussion started by: aix_admin_007
3 Replies

7. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

8. UNIX for Dummies Questions & Answers

Extracting 22-character strings from text using sed/awk?

Here is my task, I feel sure this can be accomplished with see/awk but can't seem to figure out how. I have large flat file from which I need to extract every case of a pairing of characters (GG) in this case PLUS the previous 20 characters. The output should be a list (which I plan to make... (17 Replies)
Discussion started by: Twinklefingers
17 Replies

9. Shell Programming and Scripting

How to remove certain character strings with awk?

Hi all, I need to remove DBPATH= and /db from the string below using awk (or sed, as it also exists on the machine). Input: DBPATH=/some/path/database/db Desired output: /some/path/database Thank you! (8 Replies)
Discussion started by: ejianu
8 Replies

10. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies
Mojo::Transaction::WebSocket(3pm)			User Contributed Perl Documentation			 Mojo::Transaction::WebSocket(3pm)

NAME
Mojo::Transaction::WebSocket - WebSocket transaction container SYNOPSIS
use Mojo::Transaction::WebSocket; my $ws = Mojo::Transaction::WebSocket->new; DESCRIPTION
Mojo::Transaction::WebSocket is a container for WebSocket transactions as described in RFC 6455. Note that 64bit frames require a Perl with 64bit integer support, or they are limited to 32bit. EVENTS
Mojo::Transaction::WebSocket inherits all events from Mojo::Transaction and can emit the following new ones. "drain" $ws->on(drain => sub { my $ws = shift; ... }); Emitted once all data has been sent. $ws->on(drain => sub { my $ws = shift; $ws->send(time); }); "frame" $ws->on(frame => sub { my ($ws, $frame) = @_; ... }); Emitted when a WebSocket frame has been received. $ws->unsubscribe('frame'); $ws->on(frame => sub { my ($ws, $frame) = @_; say "FIN: $frame->[0]"; say "RSV1: $frame->[1]"; say "RSV2: $frame->[2]"; say "RSV3: $frame->[3]"; say "Opcode: $frame->[4]"; say "Payload: $frame->[5]"; }); "message" $ws->on(message => sub { my ($ws, $message) = @_; ... }); Emitted when a complete WebSocket message has been received. $ws->on(message => sub { my ($ws, $message) = @_; say "Message: $message"; }); ATTRIBUTES
Mojo::Transaction::WebSocket inherits all attributes from Mojo::Transaction and implements the following new ones. "handshake" my $handshake = $ws->handshake; $ws = $ws->handshake(Mojo::Transaction::HTTP->new); The original handshake transaction, defaults to a Mojo::Transaction::HTTP object. "masked" my $masked = $ws->masked; $ws = $ws->masked(1); Mask outgoing frames with XOR cipher and a random 32bit key. "max_websocket_size" my $size = $ws->max_websocket_size; $ws = $ws->max_websocket_size(1024); Maximum WebSocket message size in bytes, defaults to the value of the "MOJO_MAX_WEBSOCKET_SIZE" environment variable or 262144. METHODS
Mojo::Transaction::WebSocket inherits all methods from Mojo::Transaction and implements the following new ones. "new" my $multi = Mojo::Content::MultiPart->new; Construct a new Mojo::Transaction::WebSocket object and subscribe to "frame" event with default message parser, which also handles "PING" and "CLOSE" frames automatically. "build_frame" my $bytes = $ws->build_frame($fin, $rsv1, $rsv2, $rsv3, $op, $payload); Build WebSocket frame. # Continuation frame with FIN bit and payload say $ws->build_frame(1, 0, 0, 0, 0, 'World!'); # Text frame with payload say $ws->build_frame(0, 0, 0, 0, 1, 'Hello'); # Binary frame with FIN bit and payload say $ws->build_frame(1, 0, 0, 0, 2, 'Hello World!'); # Close frame with FIN bit and without payload say $ws->build_frame(1, 0, 0, 0, 8, ''); # Ping frame with FIN bit and payload say $ws->build_frame(1, 0, 0, 0, 9, 'Test 123'); # Pong frame with FIN bit and payload say $ws->build_frame(1, 0, 0, 0, 10, 'Test 123'); "client_challenge" my $success = $ws->client_challenge; Check WebSocket handshake challenge. "client_handshake" $ws->client_handshake; WebSocket handshake. "client_read" $ws->client_read($data); Read raw WebSocket data. "client_write" my $chunk = $ws->client_write; Raw WebSocket data to write. "connection" my $connection = $ws->connection; Alias for "connection" in Mojo::Transaction. "finish" $ws = $ws->finish; Finish the WebSocket connection gracefully. "is_websocket" my $true = $ws->is_websocket; True. "kept_alive" my $kept_alive = $ws->kept_alive; Alias for "kept_alive" in Mojo::Transaction. "local_address" my $local_address = $ws->local_address; Alias for "local_address" in Mojo::Transaction. "local_port" my $local_port = $ws->local_port; Alias for "local_port" in Mojo::Transaction. "parse_frame" my $frame = $ws->parse_frame($bytes); Parse WebSocket frame. # Parse single frame and remove it from buffer my $frame = $ws->parse_frame($buffer); say "FIN: $frame->[0]"; say "RSV1: $frame->[1]"; say "RSV2: $frame->[2]"; say "RSV3: $frame->[3]"; say "Opcode: $frame->[4]"; say "Payload: $frame->[5]"; "remote_address" my $remote_address = $ws->remote_address; Alias for "remote_address" in Mojo::Transaction. "remote_port" my $remote_port = $ws->remote_port; Alias for "remote_port" in Mojo::Transaction. "req" my $req = $ws->req; Alias for "req" in Mojo::Transaction. "res" my $res = $ws->res; Alias for "res" in Mojo::Transaction. "resume" $ws = $ws->resume; Alias for "resume" in Mojo::Transaction. "send" $ws->send({binary => $bytes}); $ws->send({text => $bytes}); $ws->send([$fin, $rsv1, $rsv2, $rsv3, $op, $payload]); $ws->send('Hi there!'); $ws->send('Hi there!' => sub {...}); Send message or frame non-blocking via WebSocket, the optional drain callback will be invoked once all data has been written. # Send "Ping" frame $ws->send([1, 0, 0, 0, 9, 'Hello World!']); "server_handshake" $ws->server_handshake; WebSocket handshake. "server_read" $ws->server_read($data); Read raw WebSocket data. "server_write" my $chunk = $ws->server_write; Raw WebSocket data to write. DEBUGGING
You can set the "MOJO_WEBSOCKET_DEBUG" environment variable to get some advanced diagnostics information printed to "STDERR". MOJO_WEBSOCKET_DEBUG=1 SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::Transaction::WebSocket(3pm)
All times are GMT -4. The time now is 04:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy