11-13-2008
Read a string with leading spaces and find the length of the string
HI
In my script, i am reading the input from the user and want to find the length of the string.
The input may contain leading spaces. Right now, when leading spaces are there, they are not counted.
Kindly help me
My script is like below. I am using the ksh.
#!/usr/bin/ksh
echo "enter your value"
read "A"
len=echo ${#A}
echo "length of the string you entered is $len"
output:
enter your value
asdf
length of the string you entered is 4
NOte: I have entered 8 char (4 spaces + 4 char)
Kindly help me
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi guys, I hope you can help me with my problem.
I have a text file that contains lines like this:
78 ANGELO -809.05
79 ANGELO2 -5,000.06
I need to find all occurences of amounts that are negative and replace them with x's
78 ANGELO xxxxxxx
79... (4 Replies)
Discussion started by: amangeles
4 Replies
2. Shell Programming and Scripting
Hello All,
Plz help me with:
I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies
3. Shell Programming and Scripting
Hi,
Could someone has any suggestions on this? When read a line from a file, I need to check the first char in the line, it could be a space or any char. But the leading spaces are removed by read.
Thanks. (2 Replies)
Discussion started by: momi
2 Replies
4. Shell Programming and Scripting
Hi ,
I have a file named "sample" having the data as follows.
"663005487","USD",0,1,"NR"
If i give like
a=`awk -F ',' '{printf length($2)}' sample`
(Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5.
How to do this..... (2 Replies)
Discussion started by: jayakumarrt
2 Replies
5. Shell Programming and Scripting
how to find the string length in solaris machine. (4 Replies)
Discussion started by: din_annauniv
4 Replies
6. Programming
Hi All
I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies
7. Programming
Hi all,
We use strlen() fun provided by library to find the length of a string.
Looking inside of it, it has some different mechanism to find the length of string.
Normally, we scan the string byte by byte until the '\0' character. It takes a logn time to count length.
The Library strlen()... (2 Replies)
Discussion started by: yogeshrl9072
2 Replies
8. Shell Programming and Scripting
Solaris, ksh
I have a .csv file I am trying to clean up before loading into the database. The file contains comma separated columns that have leading spaces which I need to remove. The trouble is, some columns that should not be touched are strings which happen to have the same pattern in them. ... (4 Replies)
Discussion started by: gary_w
4 Replies
9. Shell Programming and Scripting
Hi,
I have a record of length 200 bytes and values filled is only 100 bytes and remaining 100 spaces is occupied by spaces. In script wen i try to find the length of the entire record it should get as 200 not 100. i tried using length and wc -c but it doesnt work can anyone have any idea on... (3 Replies)
Discussion started by: Pranaveen
3 Replies
10. Shell Programming and Scripting
Hi all,
I wanted to find and replace an email id from entire directory structure on a Linux server. I found that find . -type f -print0 | xargs -0 sed -i 's/abc@yahoo.com/xyz@gmail.com/g' would do it perfectly.
But my search criteria has extended and now I want to search for a string1 like... (2 Replies)
Discussion started by: pat_pramod
2 Replies
LEARN ABOUT DEBIAN
netsds::util::string
NetSDS::Util::String(3pm) User Contributed Perl Documentation NetSDS::Util::String(3pm)
NAME
NetSDS::Util::String - string prcessing routines
SYNOPSIS
use NetSDS::Util::String qw();
# Read from standard input
my $string = <STDIN>;
# Encode string to internal structure
$string = string_encode($tring);
DESCRIPTION
"NetSDS::Util::String" module contains functions may be used to quickly solve string processing tasks like parsing, recoding, formatting.
As in other NetSDS modules standard encoding is UTF-8.
EXPORTED FUNCTIONS
str_encode($str[, $encoding]) - encode string to internal UTF-8
By default this function treat first argument as byte string in UTF-8 and return it's internal Unicode representation.
In case of external character set isn't UTF-8 it should be added as second argument of function.
# Convert UTF-8 byte string to internal Unicode representation
$uni_string = str_encode($byte_string);
# Convert KOI8-U byte string to internal
$uni_string = str_encode($koi8_string, 'KOI8-U');
After "str_encode()" it's possible to process this string correctly including regular expressions. All characters will be understood as
UTF-8 symbols instead of byte sequences.
str_decode($str[, $encoding]) - decode internal UTF-8 to byte string
By default this function treat first argument as string in internal UTF-8 and return it in byte string (external) representation.
In case of external character set isn't UTF-8 it should be added as second argument of function.
# Get UTF-8 byte string from internal Unicode representation
$byte_string = str_decode($uni_string);
# Convert to KOI8-U byte string from internal Unicode
$koi8_string = str_encode($uni_string, 'KOI8-U');
It's recommended to use "str_encode()" when preparing data for communication with external systems (especially networking).
str_recode($str, $FROM_ENC[, $TO_ENC]) - recode string
Translate string between different encodings. If target encoding is not set UTF-8 used as default one.
str_trim($str) - remove leading/trailing space characters
$orig_str = " string with spaces ";
$new_str = str_trim($orig_str);
# Output: "string with spaces"
print $new_str;
str_trim_left($str) - removes leading whitespaces
This function is similar to "str_trim()" except of it removes only leading space characters and leave trailing ones.
str_trim_right($str) - removes trailing whitespaces
This function is similar to "str_trim()" except of it removes only trailing space characters and leave leading ones.
str_clean($str) - clean string from extra spaces
Function is similar to "str_trim()" but also changes all spacing chains inside string to single spaces.
str_camelize($strin)
If pass undef - return undef. If pass '' - return ''.
Examples:
# returns 'getValue'
str_camelize( 'get_value' )
# returns 'addUserAction'
str_camelize( 'ADD_User_actION' )
str_decamelize(...)
If pass undef - return undef. If pass '' - return ''.
Examples:
# returns 'get_value'
str_decamelize( 'getValue' )
EXAMPLES
None yet
BUGS
Unknown yet
TODO
Implement examples and tests.
SEE ALSO
Encode, perlunicode
AUTHORS
Valentyn Solomko <pere@pere.org.ua>
Michael Bochkaryov <misha@rattler.kiev.ua>
perl v5.12.4 2011-08-27 NetSDS::Util::String(3pm)