Sponsored Content
Top Forums Shell Programming and Scripting Removing last character of string Post 302365477 by panyam on Tuesday 27th of October 2009 07:22:32 AM
Old 10-27-2009
Quote:
Originally Posted by kinny
Hi ,
I have a file with the following contents in file test1.txt .
Code:
AMY_MTT_240Y001,N60_PG2_10G001,A2H_P3H_10G002,7C7_7D7_NP1,A2E_PV0_10G002,L78_PG1_64S001,A2H_P2M_NP2,LDN_YSN_64S001,WV6_WYV_64
S801,LY9_PV0_64S-R2052P,L78_PV0_64S-R2042,L78_PYE_64S-R2080,GVV_NW8_64S002,LY9_PV0_64S-UPNE1,DIS_MTP_DL72INTL,PVU_WV6_10G002,
DQE_NYY_NP6,2CS_LDN_NP1,C8L_LDN_NP1,2CS_LDN_NP2,2CS_LDN_NP3,D4O_LDN_NP1,AEQ_FR1_10G001,LDP_LE0_DL75INTL,A2H_P3H_NP2,A2H_P2M_N
P1,KS9_LDN_NP1,8BV_LDP_DL71INTL,AGA_FVP_DL71INTL,KSE_LDN_NP3,8MV_FVP_DL71INTL,8BV_FVP_DL71INTL,FV0_MTT_30N301

I want to display only those names that have "_DL" in them.

I came up with the following command:

Code:
 cat test1.txt | tr "," "\n" | grep -i _DL | tr '\n' ","

Problem with this is there is a trailing comma. I am unable to replace the trailing comma with sed or cut or head .Can anyone suggest an alternative or how to replace the trailing comma. The following is the sed i used that failed in this case
Code:
sed 's/.$//'

Thanks in advance folks

Something like this ?..
Code:
cat test1.txt | tr "," "\n" | grep -i _DL | tr '\n' ","  | awk '{ print substr($0,1,length($0)-1) }'

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing the ^M character in VI

Hello, I am attempting to remove all the ^M characters in a file in VI. The command I am using is :1,$s/^V^M//g but it doesn't work, saying 'substitute pattern match failed'. Any ideas why? Jules (2 Replies)
Discussion started by: julesinbath
2 Replies

2. UNIX for Advanced & Expert Users

Removing first character in a string

While writing a shell script i happen to store some value in a string. Lets say the value is 59788. Now in this script i want to get the value 9788 removing the first charater 5. The original string length usually remains constant. Is there a single line command to do this or any simple way to... (4 Replies)
Discussion started by: npn
4 Replies

3. Shell Programming and Scripting

Removing character ' from a variable

Hello there, I have a variable in the form of '/example/file.txt' . I want to remove the ' characters from the beginning and the end so that the my new variable becomes /example/file.txt . How can I do it in a script? I know this is a fairly easy question, but i wasn't able to implement it. (3 Replies)
Discussion started by: sertansenturk
3 Replies

4. Shell Programming and Scripting

Korn: How to loop through a string character by character

If I have a string defined as: MyString=abcde echo $MyString How can I loop through it character by character? I haven't been able to find a way to index the string so that I loop through it. shew01 (10 Replies)
Discussion started by: shew01
10 Replies

5. Shell Programming and Scripting

Need some help removing a character from name

I have a file like this: DDD_ABCDE2AB2_1104081408.104480 I need to remove the 1 after the . in the file name so that it reads: DDD_ABCDE2AB2_1104081408.04480 Having some difficulty getting the command to work. I tried using cut -d 26 but that just doesn't work. (3 Replies)
Discussion started by: bbbngowc
3 Replies

6. UNIX for Dummies Questions & Answers

Removing a character

I need to remove square brackets from output of script. Output is: and I need to remove the square brackets so I am lett with 121 Is sed the only means to do this and if so what are the options? ...ok so far I have managed to get rid of ] by using /usr/bin/sed 's/]//' but that... (5 Replies)
Discussion started by: rob171171
5 Replies

7. UNIX for Dummies Questions & Answers

Need help removing last character of every line if certain character

I need help removing the last character of every line if it is a certain character. For example I need to get rid of a % character if it is in the last position. Input: aaa% %bbb ccc d%dd% Output should be: aaa %bbb ccc d%dd I tried this but it gets rid of all of the % characters.... (5 Replies)
Discussion started by: raptor25
5 Replies

8. Shell Programming and Scripting

removing last character

Hi, I have a file that has data something like below: A B C D ..... ...... .....and so on I am trying to bring it in one line with comma delimited something like below : A,B,C,D I tried the something below in the code section: cat File.txt | tr '\n' ',' (1 Reply)
Discussion started by: rkumar28
1 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Removing an 8 character string

Edit: Figured it out. Close the thread please. Solution: \{8}\] edit by bakunin: no need to close the thread, but i changed the title to SOLVED. Thanks for writing a follow-up. (0 Replies)
Discussion started by: unknownn
0 Replies

10. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 07:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy