Sponsored Content
Top Forums Shell Programming and Scripting truncate a string from the end Post 302299990 by daikeyang on Sunday 22nd of March 2009 08:13:55 PM
Old 03-22-2009
truncate a string from the end

hi, guys. I have a question.

If I have a long string like this:

8.0K:/home/test/brownj

How can I get a substring which starts from the last slash to the end of the string, so in this case, it will be brownj

Thank you very much for you time in advance

-Keyang
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

truncate/round down 2nd string print both

I have a file with a name and then a number: Apple 1.1 Apple 1.5 Apple 1.9 Banana 1.3 Banana 2.7 Banana 3.3 I'd like to print out the first string followed by the second number rounded down or truncated: Apple 1 Apple 1 Apple 1 Banana 1 Banana 2 Banana 3 I was trying: (3 Replies)
Discussion started by: dcfargo
3 Replies

2. UNIX for Dummies Questions & Answers

I don't want to truncate trailing spaces and ^M at the end of line

I have a script wherein I access each line of the file using a FOR loop and then perform some operations in each line. The problem is each line that gets extracted in FOR loop truncates trailing blank spaces and control characters (^M) that is present at the end of each line. I don't wan this to... (5 Replies)
Discussion started by: Shobana_s
5 Replies

3. Shell Programming and Scripting

Truncate Specific Parts of a String

How do you truncate specific parts of a string. Example: 1 This is the string Goal: This is the string As you can see I'm trying to simply remove the first two characters of the string the number one and the space between the one and the word "this." Your help is appreciated. ... (8 Replies)
Discussion started by: royarellano
8 Replies

4. Shell Programming and Scripting

Truncate string variable

Hi, I want to truncate a string variable, returned in the script. In perl I used the below and it worked. BRNo=BR12345 $BR = substr($BRNo, 2, 7) How can I do it in sh. Thanks ! (8 Replies)
Discussion started by: script2010
8 Replies

5. Shell Programming and Scripting

./TRUNCATE-PS_TXN.sh: line 54: syntax error: unexpected end of file

Hi All , My below script is for chacking vaule and then trucating table : ___________ test4@aceuatcs04:/u01/test4/SOLID/Testscript>cat TRUNCATE-PS_TXN.sh #-------------------------------------------------------------------- # Created by:Kaushlesh Yadav # Generated on: 15/07/2010 # Job... (4 Replies)
Discussion started by: kaushelsh168
4 Replies

6. Shell Programming and Scripting

Truncate all characters and numbers in string - using perl

hi, I have an data from file where it has 20110904 234516 <<hdd-10#console|0c.57,passed,5,28,READ,0,20822392,8,5,4,0,40,0,-1,0,29909,25000,835,3.3,0,0,0,0,implied,0,0,2011/9/5-2:3:17,2011/9/5-2:3:47,X292_0F15,TAP ,NQ09,J40LTG\r\r\n I want to remove characters till #console| i.e want... (1 Reply)
Discussion started by: asak
1 Replies

7. Shell Programming and Scripting

truncate string to integer or decimal

From strings stored in variables, I need to isolate and use the first numerical value contained within them. I will need to know how to produce an integer as well as a floating point decimal. It needs to work on any string regardless of what types of characters (if any) are preceding or following... (3 Replies)
Discussion started by: bradlecat
3 Replies

8. Shell Programming and Scripting

How to truncate a string to x number characters?

Hello: I have a large file which contains lines like the following: 1/t123ab, &Xx:1:1234:12345:123456@ABCDEFG... at -$100.00% /t is a tab, spaces are as indicated the string "&Xx:1:1234:12345:123456$ABCDEFG..." has a slightly variable number of numbers and letters, but it always starts... (9 Replies)
Discussion started by: Tectona
9 Replies

9. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

10. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies
Test::LongString(3pm)					User Contributed Perl Documentation				     Test::LongString(3pm)

NAME
Test::LongString - tests strings for equality, with more helpful failures SYNOPSIS
use Test::More tests => 1; use Test::LongString; like_string( $html, qr/(perl|cpan).org/ ); # Failed test (html-test.t at line 12) # got: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"... # length: 58930 # doesn't match '(?-xism:(perl|cpan).org)' DESCRIPTION
This module provides some drop-in replacements for the string comparison functions of Test::More, but which are more suitable when you test against long strings. If you've ever had to search for text in a multi-line string like an HTML document, or find specific items in binary data, this is the module for you. FUNCTIONS
is_string( $string, $expected [, $label ] ) "is_string()" is equivalent to "Test::More::is()", but with more helpful diagnostics in case of failure. o It doesn't print the entire strings in the failure message. o It reports the lengths of the strings that have been compared. o It reports the length of the common prefix of the strings. o It reports the line and column the strings started to differ on. o In the diagnostics, non-ASCII characters are escaped as "x{xx}". For example: is_string( $soliloquy, $juliet ); # Failed test (soliloquy.t at line 15) # got: "To be, or not to be: that is the question:x{0a}Whether"... # length: 1490 # expected: "O Romeo, Romeo,x{0a}wherefore art thou Romeo?x{0a}Deny thy"... # length: 154 # strings begin to differ at char 1 (line 1 column 1) is_string_nows( $string, $expected [, $label ] ) Like "is_string()", but removes whitepace (in the "s" sense) from the arguments before comparing them. like_string( $string, qr/regex/ [, $label ] ) unlike_string( $string, qr/regex/ [, $label ] ) "like_string()" and "unlike_string()" are replacements for "Test::More:like()" and "unlike()" that only print the beginning of the received string in the output. Unfortunately, they can't print out the position where the regex failed to match. like_string( $soliloquy, qr/Romeo|Juliet|Mercutio|Tybalt/ ); # Failed test (soliloquy.t at line 15) # got: "To be, or not to be: that is the question:x{0a}Whether"... # length: 1490 # doesn't match '(?-xism:Romeo|Juliet|Mercutio|Tybalt)' contains_string( $string, $substring [, $label ] ) "contains_string()" searches for $substring in $string. It's the same as "like_string()", except that it's not a regular expression search. contains_string( $soliloquy, "Romeo" ); # Failed test (soliloquy.t at line 10) # searched: "To be, or not to be: that is the question:x{0a}Whether"... # and can't find: "Romeo" As of version 0.12, "contains_string()" will also report the Longest Common SubString (LCSS) found in $string and, if the LCSS is short enough, the surroundings will also be shown under LCSS Context. This should help debug tests for really long strings like HTML output, so you'll get something like: contains_string( $html, '<div id="MainContent">' ); # Failed test at t/foo.t line 10. # searched: "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric"... # can't find: "<div id="MainContent">" # LCSS: "ainContent"" # LCSS context: "dolor sit amet</span>x{0a}<div id="mainContent" class=" You can turn off LCSS reporting by setting $Test::LongString::LCSS to 0, or by specifying an argument to "use": use Test::LongString lcss => 0; lacks_string( $string, $substring [, $label ] ) "lacks_string()" makes sure that $substring does NOT exist in $string. It's the same as "like_string()", except that it's not a regular expression search. lacks_string( $soliloquy, "slings" ); # Failed test (soliloquy.t at line 10) # searched: "To be, or not to be: that is the question:x{0a}Whether"... # and found: "slings" # at position: 147 (line 3 column 4) CONTROLLING OUTPUT
By default, only the first 50 characters of the compared strings are shown in the failure message. This value is in $Test::LongString::Max, and can be set at run-time. You can also set it by specifying an argument to "use": use Test::LongString max => 100; When the compared strings begin to differ after a large prefix, Test::LongString will not print them from the beginning, but will start at the middle, more precisely at $Test::LongString::Context characters before the first difference. By default this value is 10 characters. If you want Test::LongString to always print the beginning of compared strings no matter where they differ, undefine $Test::LongString::Context. When computing line numbers this module uses " " to count line endings. This may not be appropriate for strings on your platform, and can be overridden by setting the $Test::LongString::EOL variable to a suitable regular expression (either a reference to a regular expression or a string that can be interpolated into a regular expression.) You can also set it by specifying an argument to "use": use Test::LongString eol => "x{0a}x{0c}"; AUTHOR
Written by Rafael Garcia-Suarez. Thanks to Mark Fowler (and to Joss Whedon) for the inspirational Acme::Test::Buffy. Thanks to Andy Lester for lots of patches. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. A git repository for this module is available at git://github.com/rgs/Test-LongString.git SEE ALSO
Test::Builder, Test::Builder::Tester, Test::More. perl v5.10.1 2011-02-08 Test::LongString(3pm)
All times are GMT -4. The time now is 09:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy