Remove only specific char on every line when exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove only specific char on every line when exists
# 1  
Old 03-18-2013
Remove only specific char on every line when exists

Hi
I need to remove "|" char when it's the last char of the line.

Input file:

Code:
generoso|desprendido|altruista|
abnegar|ceder|sacrificar|
abocetado-da|esbozado|
apuntado|insinuado|incompleto
abocetar|esbozar|bosquejar|
diseñar|delinear


------------------------ output need ---

Code:
generoso|desprendido|altruista
abnegar|ceder|sacrificar
abocetado-da|esbozado
apuntado|insinuado|incompleto
abocetar|esbozar|bosquejar
diseñar|delinear

I have searched in the forum but only find solutions that delete last char of all lines,

Thanks

Last edited by Scrutinizer; 03-18-2013 at 09:50 PM.. Reason: code tags; code tags (2nd time)
# 2  
Old 03-18-2013
Try:
Code:
sed 's/|$//' file

# 3  
Old 03-18-2013
try also:
Code:
awk 1 RS="[|]*\n" infile

# 4  
Old 03-19-2013
Hi,

Not working with large file about 50.000 lines, it's that possible?

Thx
# 5  
Old 03-19-2013
What is not working?
# 6  
Old 03-19-2013
Nothing change in my output file.

---------- Post updated at 12:35 PM ---------- Previous update was at 12:26 PM ----------

Code:
[root@ks200485 dic]# cat a
abacería@comercio@tienda@
abacial@monacal@monástico@
abadengo@conventual
ábaco@contador@tablero@bolillero@
tanteador@numerador@
columna@capitel@coronamiento
abad@superior@prior@rector
abadía@abadiato@monasterio@
convento@cartuja@priorato@
abajadero@cuesta@pendiente@
[root@ks200485 dic]# awk 1 RS="[@]*\n" a
abacería@comercio@tienda
abacial@monacal@monástico
abadengo@conventual
ábaco@contador@tablero@bolillero
tanteador@numerador
columna@capitel@coronamiento
abad@superior@prior@rector
abadía@abadiato@monasterio
convento@cartuja@priorato
abajadero@cuesta@pendiente
[root@ks200485 dic]# awk 1 RS="[@]*\n" test11

getting out original content of test11, it's my large file, in the same format. Maybe it's malformed, how can i fix that file?

Thx
# 7  
Old 03-19-2013
How about
Code:
sed 's/@$//' file

then?

--
The awk statement will only work with gawk or mawk, but not with regular awk, because regular awk can only use a single character in RS.

Last edited by Scrutinizer; 03-19-2013 at 02:53 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove line break at specific position

Hi, I need to remove line breaks from a file, but only the ones at specific position. Input file: this is ok this line is divided at posit ion 30. The same as this one, also position 30 the rest of lines are ok with different lengths The longest ones are always s plitted at same... (15 Replies)
Discussion started by: qranumo
15 Replies

2. Shell Programming and Scripting

Remove every line with specific string, and also the one above and below it

I would like to identify every line with a specific string, in this case: "Mamma". I would like to remove that line, and also the line above it and below it. So the below Where are all amazing Flats Look At The Great Big White Hey There Hot Mamma You Are So hot Baby I wish You were Mine... (5 Replies)
Discussion started by: phpchick
5 Replies

3. Shell Programming and Scripting

Remove line with specific character

HI Input :- Aog:0rt__dev_8 LAAXU24 vs.3 LAA40l0 ** LAAXU241 ** Output :- Aog:0rt__dev_8 LAAXU24 vs.3 Delete the line with ** (3 Replies)
Discussion started by: pareshkp
3 Replies

4. Shell Programming and Scripting

How to remove the # char form a line?

Hi, my file has below details and I want remove the # char from only specific line. #TEST:00:START #TEST1:01:INPROCESS #TEST2:02:ABOUTTO #TEST3:03:COMP i.e if want remove the # from 2nd line then file to be updated as #TEST:00:START TEST1:01:INPROCESS #TEST2:02:ABOUTTO... (6 Replies)
Discussion started by: sandyrajh
6 Replies

5. UNIX for Dummies Questions & Answers

Remove First Char from Line in File Only if it's a comma

I have a file, I need to remove the first character of each line, but only if it's a comma. I don't want to delete any other commas in each line. Trying cat or sed but I really don't know them very well, would love some help. This removes the first comma, but it removes the first comma no... (6 Replies)
Discussion started by: Cynthia
6 Replies

6. Shell Programming and Scripting

remove unwanted specific line range

Hello everyone...I have large txt file and I would like to remove unwanted specific line. My data is like this: So I would like to remove from line below No. until line reassambled like this: Thanks... (4 Replies)
Discussion started by: taxi
4 Replies

7. Shell Programming and Scripting

How to remove a specific line matching pattern1 and pattern2 ?

Hi, I have a file like below: . . . . Jack is going home Jack is going to school Jack is sleeping Jack is eating dinner John is going home John is eating breakfast . . . The specific line is: Jack is going home (2 Replies)
Discussion started by: salih81
2 Replies

8. Shell Programming and Scripting

remove a specific line in a LARGE file

Hi guys, i have a really big file, and i want to remove a specific line. sed -i '5d' fileThis doesn't really work, it takes a lot of time... The whole script is supposed to remove every word containing less than 5 characters and currently looks like this: #!/bin/bash line="1"... (2 Replies)
Discussion started by: blubbiblubbkekz
2 Replies

9. Shell Programming and Scripting

How to remove new line char from a string

Hi Can anyone tell me how can i remove new line character from a string. My requirement is to read a line from a file and store it to a string. read line string1=$line read line string2=$line echo $string1$string2 The result i am getting in different line. i want the output in the same... (1 Reply)
Discussion started by: sreedivia
1 Replies

10. Shell Programming and Scripting

Remove Line that contains specific string

I am looking for a way to remove any line in a text file that contains the string "Mac address". I guess you would grep and sed, but I am not sure how to do this. Thanks for you help. (3 Replies)
Discussion started by: CBarraford
3 Replies
Login or Register to Ask a Question