lookoo
March 18, 2013, 8:44pm
1
Hi
I need to remove "|" char when it's the last char of the line.
Input file:
generoso|desprendido|altruista|
abnegar|ceder|sacrificar|
abocetado-da|esbozado|
apuntado|insinuado|incompleto
abocetar|esbozar|bosquejar|
dise�ar|delinear
------------------------ output need ---
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
lookoo
March 19, 2013, 1:19pm
4
Hi,
Not working with large file about 50.000 lines, it's that possible?
Thx
lookoo
March 19, 2013, 1:35pm
6
Nothing change in my output file.
---------- Post updated at 12:35 PM ---------- Previous update was at 12:26 PM ----------
[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
How about
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.
lookoo
March 19, 2013, 1:55pm
8
Not working it's very strange I think my file it's malformated
RudiC
March 19, 2013, 2:17pm
9
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...
lookoo
March 19, 2013, 2:43pm
10
Infile
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
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.
#!/bin/bash
count=1
while read -r line ; do
echo $(echo $line) >> clean.txt
done < test10
sed 's/@$//' clean.txt >> clean2.txt
Thx
RudiC
March 19, 2013, 2:46pm
11
THERE you are! Use Scrutinizer's proposal, slightly extended:
sed 's/@\r$//' file
Not sure if your sed accepts that \r notation; in bash, try <ctrl>V<ctrl>M, then...
\r
would work in GNU sed, but not in regular sed.
With regular sed you could
sed "s/@$(printf "\r")\$//"
or, knowing that every line ends in \r\n
just:
sed 's/@.$//'