07-28-2006
Thank you. It works
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Friends,
Can any one help with this issue:
How to trim spaces for each line at the end,
Like I have a file in this format.
EMP1 SMITH 46373 5 STREET HOWARD 74636
EMP2 JONES 5454 { these are spaces ........}
EMP3 SMITH 46373 5 STREET HOWARD 74636
EMP4 JON 2554 { these are... (1 Reply)
Discussion started by: sbasetty
1 Replies
2. UNIX for Advanced & Expert Users
am get a value like ' 15' in a variable
what is the easiest method i can follow to strip 15 out (3 Replies)
Discussion started by: anumkoshy
3 Replies
3. Programming
I am coding a C program to read a plain text file. There are a lot of blank fields or a string with white spaces. I want to know is there such a function called trim() in C to clean the white space around a string? Or some other way can do this efficiently? Thanks. (18 Replies)
Discussion started by: hxm1303
18 Replies
4. Shell Programming and Scripting
Hi,
I'm new to shell programming. Need some help in the following requirement:
I have a file origFile.txt with values:
origFile.txt
.00~ 145416.02~ xyz~ ram kishor
.35~ 765.76~ anh reid~ kishna kerry
Now each row in the file has value for 4 columns with "~" as... (7 Replies)
Discussion started by: badrimohanty
7 Replies
5. Shell Programming and Scripting
Hi,
I have a file origFile.txt with values:
origFile.txt
.00~ 145416.02~ xyz~ ram kishor ~? ~ ~783.9
.35~ 765.76~ anh reid~ kelly woodburg ~nancy ~ ~?
Now each row in the file has value for 7 columns with "~" as delimiter.
The requirement was
i)I need to erase the blank spaces between... (2 Replies)
Discussion started by: badrimohanty
2 Replies
6. Shell Programming and Scripting
Hi,
I am using gawk (--posix) for extracting some information from something like the following lines (in a text file):
sms_snath_hp_C/CORE BUILD PREREQUISITE:
total 1556
drwxrwxrwx 2 sn sn 4096 2008-06-27 08:31 ./
drwxrwxrwx 13 sn sn 4096 2009-07-22 14:48 ../
-rwxrwxrwx 1 sn sn ... (14 Replies)
Discussion started by: shri_nath
14 Replies
7. Shell Programming and Scripting
HI Guys
I have written a script using awk to split a file based on some identifier and renaming the file based on two values from specific length. ts a fixed width file.
When I am trying to fetch the values
a = substr($0,11,10)
b = substr($0,21,5);
i am getting spaces in a and b values .... (6 Replies)
Discussion started by: manish8484
6 Replies
8. Shell Programming and Scripting
Hi,
Consider the data (FS = |):
1| England |end
2| New Zealand |end
3|Australia|end
4| Some Made Up Country |end
5| West Indies|end
I want the output to be (i.e. without the leading and trailing white space from $2)
England
New Zealand
Australia
Some Made Up Country
West... (4 Replies)
Discussion started by: Storms
4 Replies
9. Shell Programming and Scripting
All,
i am comparing the output of one command to a numberic
if ]
but my problem is the output of follwoing is but but has some leading columns. I don't have any problme in LINUX and HP-UX. But only in AIX i am getting the leading spaces. I have developed my script on LINUX but when... (4 Replies)
Discussion started by: rcc50886
4 Replies
10. UNIX for Beginners Questions & Answers
I have a file like this.
hari,corporationbank,2234356,syndicate
ravi,indian bank,4567900000000,indianbank,accese
raju,statebank of hyderabad,565866666666666,pause
Here each record has different record length and there are blank spaces... (8 Replies)
Discussion started by: kshari8888
8 Replies
LEARN ABOUT DEBIAN
text::trim
Text::Trim(3pm) User Contributed Perl Documentation Text::Trim(3pm)
NAME
Text::Trim - remove leading and/or trailing whitespace from strings
VERSION
version 1.02
SYNOPSIS
use Text::Trim;
$text = " important data
";
$data = trim $text;
# now $data contains "important data" and $text is unchanged
# or:
trim $text; # work in-place, $text now contains "important data"
@lines = <STDIN>;
rtrim @lines; # remove trailing whitespace from all lines
# Alternatively:
@lines = rtrim <STDIN>;
# Or even:
while (<STDIN>) {
trim; # Change $_ in place
# ...
}
DESCRIPTION
This module provides functions for removing leading and/or trailing whitespace from strings. It is basically a wrapper around some simple
regexes with a flexible context-based interface.
EXPORTS
All functions are exported by default.
CONTEXT HANDLING
void context
Functions called in void context change their arguments in-place
trim(@strings); # All strings in @strings are trimmed in-place
ltrim($text); # remove leading whitespace on $text
rtrim; # remove trailing whitespace on $_
No changes are made to arguments in non-void contexts.
list context
Values passed in are changed and returned without affecting the originals.
@result = trim(@strings); # @strings is unchanged
@result = rtrim; # @result contains rtrimmed $_
($result) = ltrim(@strings); # like $result = ltrim($strings[0]);
scalar context
As list context but multiple arguments are stringified before being returned. Single arguments are unaffected. This means that under
these circumstances, the value of $" ($LIST_SEPARATOR) is used to join the values. If you don't want this, make sure you only use single
arguments when calling in scalar context.
@strings = (" hello
", " there
");
$trimmed = trim(@strings);
# $trimmed = "hello there"
local $" = ', ';
$trimmed = trim(@strings);
# Now $trimmed = "hello, there"
$trimmed = rtrim;
# $trimmed = $_ minus trailing whitespace
Undefined values
If any of the functions are called with undefined values, the behaviour is in general to pass them through unchanged. When stringifying a
list (calling in scalar context with multiple arguments) undefined elements are excluded, but if all elements are undefined then the return
value is also undefined.
$foo = trim(undef); # $foo is undefined
$foo = trim(undef, undef); # $foo is undefined
@foo = trim(undef, undef); # @foo contains 2 undefined values
trim(@foo) # @foo still contains 2 undefined values
$foo = trim('', undef); # $foo is ''
FUNCTIONS
trim
Removes leading and trailing whitespace from all arguments, or $_ if none are provided.
rtrim
Like trim() but removes only trailing (right) whitespace.
ltrim
Like trim() but removes only leading (left) whitespace.
UNICODE
Because this module is implemented using perl regular expressions, it is capable of recognising and removing unicode whitespace characters
(such as non-breaking spaces) from scalars with the utf8 flag on. See Encode for details about the utf8 flag.
Note that this only applies in the case of perl versions after 5.8.0 or so.
SEE ALSO
Brent B. Powers' String::Strip performs a similar function in XS.
AUTHOR
Matt Lawrence <mattlaw@cpan.org>
ACKNOWLEDGEMENTS
Terrence Brannon <metaperl@gmail.com> for bringing my attention to String::Strip and suggesting documentation changes.
perl v5.10.1 2010-06-07 Text::Trim(3pm)