Sponsored Content
Top Forums Shell Programming and Scripting Clearing leading and trailing blanks from a string in C Shell Post 302633325 by Chubler_XL on Tuesday 1st of May 2012 05:44:21 PM
Old 05-01-2012
How about this:

Code:
# echo "  Acme Consultants Pty Ltd   " | sed -e 's/^ *//' -e 's/ *$//' -e 's/ /_/g'
Acme_Consultants_Pty_Ltd


Last edited by Chubler_XL; 05-01-2012 at 06:44 PM.. Reason: Fixed line wrap
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Leading and Trailing Spaces

Hi, how to i remove leading and trailing spaces from a line? the spaces can be behind or in front of any field or line example of a line in the input data: Amy Reds , 100 , /bin/sh how to i get it to be: Amy Read,100,/bin/sh i saw something on this on the Man pages for AWK... (7 Replies)
Discussion started by: sleepster
7 Replies

2. UNIX for Advanced & Expert Users

FTP Between UNIX & Windows drops leading blanks

I am using ftp on Solaris to transfer files to Windows 2000 that have leading blanks in the name (ex. " 12345A4444.BIN"). When they get to Windows the leading blanks are stripped off. Has anyone encountered this and is there a fix? If I use Hummingbird it is ok but that is not an option for... (6 Replies)
Discussion started by: worf52
6 Replies

3. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

4. Shell Programming and Scripting

how to remove trailing blanks, tabs

Hi I need to delete trailing spaces, tabs and unprintable charactes from the file. This file has a number of blank lines which should be left intact. Another words I am trying to remove the junk at the end of each line. Does anyone come across the similar problem? Thanks a lot for any help -A (3 Replies)
Discussion started by: aoussenko
3 Replies

5. Shell Programming and Scripting

remove trailing and leading spaces using tr command

Dear All, can you please advice how do i remove trailing and leading spaces from a pipe-delimited file using "tr" command the below cmd, i tried removed all spaces tr -d ' '<s1.txt>s2.txt1 Many thx Suresh (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

6. Shell Programming and Scripting

Removing leading and trailing spaces only in PERL

Hi All, I have a file with the following contents with multiple lines 172445957| 000005911|8| 400 Peninsula Ave.#1551 | And,K |935172445957|000005911 607573888 |000098536 | 2|Ane, B |J |Ane |1868 |19861206|20090106|20071001 I want to trim the "leading and trailing spaces only" from... (2 Replies)
Discussion started by: kumar04
2 Replies

7. Shell Programming and Scripting

Help to move leading negative sign to trailing position

Hi All, I am having a file which contains negative numbers, wht i am doing is re-formattting the file(moving few columns and add few hard codings between), while reformatting i would want the negative numbers to have the sign as trailing rather than leading. Existing -2400.00 34 0.00... (11 Replies)
Discussion started by: selvankj
11 Replies

8. Shell Programming and Scripting

Leading blanks

Hi Ich have a list as follows 73 5 100 45 81 4 and I would like to have an output (on screen) like that 73 5 100 45 81 4 (6 Replies)
Discussion started by: lazybaer
6 Replies

9. Shell Programming and Scripting

Remove leading and trailing spaces from a file

Hi, I am trying to remove leading and trailing spaces from a file using awk but somehow I have not been able to do it. Here is the data that I want to trim. 07/12/2017 15:55:00 |entinfdev |AD ping Time ms | .474| 1.41| .581|green |flat... (9 Replies)
Discussion started by: svajhala
9 Replies

10. Shell Programming and Scripting

How to remove leading and trailing spaces for variable in shell script?

Hi I have variable named tablename. The value to tablename variable has leading and trailing white spaces. How to remove the leading and training white spaces and write the value of the tablename without space to a file using shell script. ( for e.g. tablename= yyy ) INPUT ... (10 Replies)
Discussion started by: pottic
10 Replies
IO::Pty::Easy(3pm)					User Contributed Perl Documentation					IO::Pty::Easy(3pm)

NAME
IO::Pty::Easy - Easy interface to IO::Pty VERSION
version 0.09 SYNOPSIS
use IO::Pty::Easy; my $pty = IO::Pty::Easy->new; $pty->spawn("nethack"); while ($pty->is_active) { my $input = # read a key here... $input = 'Elbereth' if $input eq "ce"; my $chars = $pty->write($input, 0); last if defined($chars) && $chars == 0; my $output = $pty->read(0); last if defined($output) && $output eq ''; $output =~ s/Elbereth/e[35mElberethe[m/; print $output; } $pty->close; DESCRIPTION
"IO::Pty::Easy" provides an interface to IO::Pty which hides most of the ugly details of handling ptys, wrapping them instead in simple spawn/read/write commands. "IO::Pty::Easy" uses IO::Pty internally, so it inherits all of the portability restrictions from that module. METHODS
new(%params) The "new" constructor initializes the pty and returns a new "IO::Pty::Easy" object. The constructor recognizes these parameters: handle_pty_size A boolean option which determines whether or not changes in the size of the user's terminal should be propageted to the pty object. Defaults to true. def_max_read_chars The maximum number of characters returned by a "read()" call. This can be overridden in the "read()" argument list. Defaults to 8192. raw A boolean option which determines whether or not to call "set_raw()" in IO::Pty after "spawn()". Defaults to true. spawn(@argv) Fork a new subprocess, with stdin/stdout/stderr tied to the pty. The argument list is passed directly to "exec()". Returns true on success, false on failure. read($timeout, $length) Read data from the process running on the pty. "read()" takes two optional arguments: the first is the number of seconds (possibly fractional) to block for data (defaults to blocking forever, 0 means completely non-blocking), and the second is the maximum number of bytes to read (defaults to the value of "def_max_read_chars", usually 8192). The requirement for a maximum returned string length is a limitation imposed by the use of "sysread()", which we use internally. Returns "undef" on timeout, the empty string on EOF, or a string of at least one character on success (this is consistent with "sysread()" and Term::ReadKey). write($buf, $timeout) Writes a string to the pty. The first argument is the string to write, which is followed by one optional argument, the number of seconds (possibly fractional) to block for, taking the same values as "read()". Returns undef on timeout, 0 on failure to write, or the number of bytes actually written on success (this may be less than the number of bytes requested; this should be checked for). is_active Returns whether or not a subprocess is currently running on the pty. kill($sig, $non_blocking) Sends a signal to the process currently running on the pty (if any). Optionally blocks until the process dies. "kill()" takes two optional arguments. The first is the signal to send, in any format that the perl "kill()" command recognizes (defaulting to "TERM"). The second is a boolean argument, where false means to block until the process dies, and true means to just send the signal and return. Returns 1 if a process was actually signaled, and 0 otherwise. close Kills any subprocesses and closes the pty. No other operations are valid after this call. handle_pty_size Read/write accessor for the "handle_pty_size" option documented in the constructor options. def_max_read_chars Read/write accessor for the "def_max_read_chars" option documented in the constructor options. pid Returns the pid of the process currently running in the pty, or undef if no process is running. BUGS
No known bugs. Please report any bugs through RT: email "bug-io-pty-easy at rt.cpan.org", or browse to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Pty-Easy <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-Pty-Easy>. SEE ALSO
IO::Pty (This module is based heavily on the try script bundled with IO::Pty.) Expect IO::Pty::HalfDuplex SUPPORT
You can find this documentation for this module with the perldoc command. perldoc IO::Pty::Easy You can also look for information at: o AnnoCPAN: Annotated CPAN documentation http://annocpan.org/dist/IO-Pty-Easy <http://annocpan.org/dist/IO-Pty-Easy> o CPAN Ratings http://cpanratings.perl.org/d/IO-Pty-Easy <http://cpanratings.perl.org/d/IO-Pty-Easy> o RT: CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Pty-Easy <http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Pty-Easy> o Search CPAN http://search.cpan.org/dist/IO-Pty-Easy <http://search.cpan.org/dist/IO-Pty-Easy> AUTHOR
Jesse Luehrs <doy at tozt dot net> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Jesse Luehrs. 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-05 IO::Pty::Easy(3pm)
All times are GMT -4. The time now is 08:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy