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
# 8  
Old 03-19-2013
Not working Smilie it's very strange I think my file it's malformated
# 9  
Old 03-19-2013
Do you have windows control chars in that file, like <CR> at the end of line? Post a few lines of cat -et file output...
# 10  
Old 03-19-2013
Infile

Code:
apoyo@sostén@arbotante
contragolpe@contraofensiva@
contrahacer@falsificar@remedar@
copiar@imitar@adulterar@
contrahecho-cha@deforme@
jorobado@malhecho@estropeado@
desproporcionado@
contraindicación@reserva@
recusación@anulación@supresión
contraorden@revocación@
contrapartida@compensación
contrapelo(a)@ensentido
contrapeso@compensación@
equiparación@igualación@
equilibrio@nivelación@

cat -et result

Code:
apoyo@sostM-in@arbotante^M$
contragolpe@contraofensiva@^M$
contrahacer@falsificar@remedar@^M$
copiar@imitar@adulterar@^M$
contrahecho-cha@deforme@^M$
jorobado@malhecho@estropeado@^M$
desproporcionado@^M$
contraindicaciM-sn@reserva@^M$
recusaciM-sn@anulaciM-sn@supresiM-sn^M$
contraorden@revocaciM-sn@^M$
contrapartida@compensaciM-sn^M$
contrapelo(a)@ensentido^M$
contrapeso@compensaciM-sn@^M$
equiparaciM-sn@igualaciM-sn@^M$
equilibrio@nivelaciM-sn@^M$

Yes, there are some strange chars ^M$

---------- Post updated at 01:43 PM ---------- Previous update was at 01:32 PM ----------

Ok, fixed, I made a little script that read line by line (bad file) and insert on a new file. Then was able to remove last char when exists.
Code:
#!/bin/bash

count=1




while read -r line ; do 

    
 echo $(echo $line) >> clean.txt
       
                 
done < test10

sed 's/@$//' clean.txt >> clean2.txt

Thx
# 11  
Old 03-19-2013
THERE you are! Use Scrutinizer's proposal, slightly extended:
Code:
sed 's/@\r$//' file

Not sure if your sed accepts that \r notation; in bash, try <ctrl>V<ctrl>M, then...
# 12  
Old 03-19-2013
\r would work in GNU sed, but not in regular sed.

With regular sed you could
Code:
sed "s/@$(printf "\r")\$//"

or, knowing that every line ends in \r\n just:
Code:
sed 's/@.$//'

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