I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following:
. But It is removing special characters exists everywhere in the file(begining,middle and end of the file). But I want to remove the special characters appearing only at the end of the each record. I do not want to delete the special characters which are present in the begining or middle of the record. The Unix operating system is AIX.Please do the needful.
Moderator's Comments:
Please use CODE tags when displaying sample input, sample output, and code segments.
Thanks
Rakesh
Hi Rakesh,
Please note that UNIX shells and utilities are very picky about spelling, capitalization, and quoting. The utility named sed will not be found if you spell it with a leading capital letter (as in Sed as shown in your sample code above) and the single-quote characters surrounding the last argument to sed must be the single-quote character that is found as the unshifted character on the key that has the double-quote character as the shifted character on a US keyboard. The pretty-printed characters in the Sed command you showed us above will cause a syntax error and a mismatched quotes error.
Also note that ^M is two characters (one that is special in some, but not all, circumstances and one that is seldom special). Some utilities will print control characters as a two-character sequence (with ^M representing the <carriage-return> character), but you can't search for control characters using these two-character sequences in a regular expression.
Also note that your specification is ambiguous. Are you trying to get rid of a single special character at the end of a line or are you trying to get rid of all adjacent special characters at the end of a line? Please give us a more precise definition of what you're trying to do and show us a small, representative sample input file (in CODE tags) that shows us what the input files you will be processing look like and show us a corresponding sample output file (in CODE tags) that shows us the output you hope to produce. Producing a list of special characters ending with "etc." leaves us guessing at what you mean by special. Is your definition of special anything that is not an alphanumeric character in your current locale? If it is, please confirm that this is what you mean. If not, please provide a definitive definition of the term special character that you are using.
Since you're converting all non-alphanumeric characters to <space>s, you seem to be indicating that <space> is to be treated as a special character. Does that mean that a single <space> or all <space>s at the end of a line should be deleted?
Your code seems to be trying to change all occurrences of two or more adjacent <space> characters to a single <space> in your output. You didn't say anything about doing that in the description of what you're trying to do. Is this a requirement or just a side effect of the way you're converting non-alphanumeric characters to <space> as an intermediate step in your algorithm?
Quote:
Originally Posted by nezabudka
Hi, rakeshp
Try this
or
Hi nezabudka,
Note that rakeshp is using AIX. The GNU sed\w escape sequence to match a "word" in a BRE is not supported by AIX (and is not allowed by the POSIX standards for any version of sed).
These 2 Users Gave Thanks to Don Cragun For This Post:
We have a unix file that contains special characters (ie. Ñ, °, É, ¿ , £ , ø ). When I try to read this file I get a codepage error and the characters are replaced by the # symbol. How do I keep the special characters from being read?
Thanks.
Ryan (3 Replies)
I don't now exactly how I did it, but I created a file named " -C "
cexdi:/home1 $ls -lt
total 1801336
-rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C
How do I delete this file ?
cexdi:/home1 $rm -C
rm: invalid option -- C
Syntax : rm filename ...
Doesn't work...... (5 Replies)
Hi all,
I have the following lines
<b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
<b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
<b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
and I would like to... (5 Replies)
Hello Team,
Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content.
----------------------------------------
Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
I have a file that has the name in one of the lines as MARíA MENDOZA in Windows. When this gets FTPed over to UNIX it appears as MAR�A MENDOZA. Is there anyway to overcome this? Its causing a issue because the file is Postional and fields are getting pushed by 2 digits..
Any help would be... (4 Replies)
Need unix commands to delete records from one file if the same record present in another file...
just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file..
tried with grep and while... (6 Replies)
Hi,
How to add trailer record at the end of the flat file in the unix ksh shell scripting
can you please let me know the procedure
Regards
Srikanth (3 Replies)
Any time I do :
ls *.txt > mytext.txt
I get something like this in the output file:
^
Tue Jan 22 16:19:19 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
t1Fam_BrOv :~>alias | grep ls
alias l.='ls -d .* --color=tty'
alias lR='ls -R'
alias la='ls -Al'
alias lc='ls -ltcr'
alias ldd='ls -ltr |... (5 Replies)
My sed is not working on deleting the entire special characters and leaving what is necessary.grep connections_per a|sed -e 's/\<\!\-\-//g'
INPUT:
<!-- <connections_per_instance>1</connections_per_instance> -->
<method>HALF</method>
<!--... (10 Replies)