Sponsored Content
Full Discussion: Remove CR from string
Top Forums Shell Programming and Scripting Remove CR from string Post 302700899 by Lord Spectre on Friday 14th of September 2012 11:42:31 AM
Old 09-14-2012
Remove CR from string

Dear community,
I have a very simple question, but I cannot figure out how to solve.
I have a simple string containing the carriage return or line feed at the end:
Code:
# echo $var
BLA BLA BLA
[CR]

Now if I want to remove the CR I can use:
Code:
echo $var|tr -d '\n\r'

Because the $var should be reported on a file, togheter with other values, how can I remove the CR directly on the $var?

I tried:
Code:
var=$(echo $var|tr -d '\n\r')

But it's not working....

---------- Post updated at 10:42 AM ---------- Previous update was at 10:34 AM ----------

Wait, let me explain better. I have a file (info.tmp) like this:
Code:
       AAAAAAAAAAAAAA
       BBBBBBBBBBBBBBB
       CCCCCCCCCCCCCCC
       DDDDDDDDDDDDDD
       INFO: ABCDEFG
       FFFFFFFFFFFFFFFFFF
       GGGGGGGGGGGGGG

I need to extract the INFO row, but with the following command I extracted also the Carriage Return:
Code:
var=$(grep -i INFO /info.tmp | sed 's/^ *//')

So, how can I remove the CR from $var ??
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

string remove

I have a script that does ls -ltr > files. like this i have 10 ls -ltr. My file x has 10 different lines with yyyy.log. I need to use this file's contents but without log at the end and i am using this in a script. Hope it is clear. Help pls Gundu (1 Reply)
Discussion started by: gundu
1 Replies

2. Shell Programming and Scripting

how to remove first two latter of any string

Hi, I have a variable with contain "fl080114". I want only "080114" into an another variable. input: name="fl080114" output: nm="080114" Please help. Thanks in advance. (2 Replies)
Discussion started by: rinku
2 Replies

3. Shell Programming and Scripting

how to remove characters from a string

Hi. for the following line: Var1=${Array} now Array has text as "{hello there}" how do I remove the {} brackets before assigning the string to Var1? Thanks. (3 Replies)
Discussion started by: shadow_boi
3 Replies

4. Shell Programming and Scripting

Remove path string from file (string contains "/")

This is the way sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc But, as far as I saw you cannot add any "/" in the string you want to remove.... So, what should I do in order to remove this path (which contains "/") ?:confused: (7 Replies)
Discussion started by: hakermania
7 Replies

5. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

6. Shell Programming and Scripting

Remove String...

Hi, All my source files are having the format of tar.gz . When we have loaded the data in our target output file, we are getting some characters also in our output file like this Actual output is: File1.dat000064400215140000315000000023001164575707100224730ustar|20110506 Expected... (2 Replies)
Discussion started by: suresh01_apk
2 Replies

7. 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

8. Shell Programming and Scripting

Remove first string

Hello, I have below data in a file and i want to remove 0 in front every digit from 1 to 9 16 08 08 16 16 16 16 08 08 16 out put should be 16 8 (2 Replies)
Discussion started by: mirwasim
2 Replies

9. Shell Programming and Scripting

Remove multiple lines from a particular string to particular string

Hi, I have a file containing the DDLs of tables in a schema. From that I need to remove all the lines from a starting string till a specific string. Here is an example. File1.txt ------------- CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS" ( "ID" NUMBER(8,0) NOT NULL ENABLE, "USER_ID"... (3 Replies)
Discussion started by: satyaatcgi
3 Replies

10. Shell Programming and Scripting

Remove not only the duplicate string but also the keyword of the string in Perl

Hi Perl users, I have another problem with text processing in Perl. I have a file below: Linux Unix Linux Windows SUN MACOS SUN SUN HP-AUX I want the result below: Unix Windows SUN MACOS HP-AUX so the duplicate string will be removed and also the keyword of the string on... (2 Replies)
Discussion started by: askari
2 Replies
Locale::Codes::LangExt(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangExt(3pm)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangExt(3pm)
All times are GMT -4. The time now is 10:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy