HOw to find special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HOw to find special characters
# 1  
Old 02-16-2012
CPU & Memory HOw to find special characters

I have flat file which has data like this
Code:
glid¿as_liste¿025175456

How can I print these lines into new file?

Last edited by methyl; 02-16-2012 at 06:42 PM.. Reason: please use code tags
# 2  
Old 02-16-2012
Sorry, your question does not make sense.
Please post sample input, expected output and an explanation of the process.
Please also post what Operating System and version you have and what Shell or programming language you prefer.

The upside-down quesion mark usually denotes a character which your display equipment cannot display. Do you know what character(s) these are?
# 3  
Old 02-16-2012
¿ Or do you mean only lines that contains ¿ ?
Code:
grep ¿ file > newfile

# 4  
Old 02-16-2012
"od -c" can help you identify those non-printable character and represent them in octal. If you want to only print those lines:
Code:
while read line
do
  echo "$line" | od -c | grep -w -e '[0-7][0-7][0-7]' > /dev/null && echo "$line"
done < your-input-file

# 5  
Old 02-16-2012
Quote:
Originally Posted by chihung
"od -c" can help you identify those non-printable character and represent them in octal. If you want to only print those lines:
Code:
while read line
do
  echo "$line" | od -c | grep -w -e '[0-7][0-7][0-7]' > /dev/null && echo "$line"
done < your-input-file

That echo statement cannot be relied upon. What if $line expands to something that looks like a command option? You can't use "--" to explicitly signal the end of option processing. printf %s "$line" is a better approach.

Perhaps it would also be a good idea to suppress od's offset with -An, since the offset's format is unspecified and could possibly be matched by grep.

AWK might be easiest to use since its regular expression flavor is required to support octal escape sequences even within bracket expressions. However, without a definition of "special characters" by the OP, that's just speculation.

Regards,
Alister

Last edited by alister; 02-16-2012 at 11:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find out special characters from xml file

Hi....I have a xml file which is having lots of special characters which I need to find out and put the distinct list of those into a text file. The list of special characters is not specific, it can be anything at different point of time. Can anyone help me to find out the same and list out? ... (10 Replies)
Discussion started by: Krishanu Saha
10 Replies

2. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

3. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

4. UNIX for Dummies Questions & Answers

find text enclosed between special characters

Hi, I'm trying to find all DISTINCT words having _mr in the line and ENCLOSED in '/'. For eg below is the text in a file.. /database/new_mr254/1 /database/rawdb/views/new_mr254/1 /database/project/rawdb/tables/new_mr232/1 /database/project/rawdb/views/new_mr253/1... (5 Replies)
Discussion started by: northwest
5 Replies

5. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

6. UNIX for Dummies Questions & Answers

Find in Files (special characters)

Well, I've searched the forum, but couldn't find an option, that would help me. I'm really a dummie in unix, so here it goes. I've got like 50k files in a single catalogue. One of them contains a string: Including the box/square brackets. I tried to find it manually, and use some search... (2 Replies)
Discussion started by: kalik
2 Replies

7. UNIX for Dummies Questions & Answers

Find and replace special characters in a file

HI All I need a shell script ehich removes all special characters from file and converts the file to UTF-* format Specail characters to be removed must be configurable. strIllegal = @"?/><,:;""'{|\\+=-)(*&^%$#@!~`"; Please help me in getting this script as my scripting skilla are... (2 Replies)
Discussion started by: sujithchandra
2 Replies

8. UNIX for Dummies Questions & Answers

Help with find and replace w/string containing special characters

Can I get some help on this please, I have looked at the many post with similar questions and have tried the solutions and they are not working for my scenario which is: I have a text file (myfile) that contains b_log=$g_log/FILENAME.log echo "Begin processing file FILENAME " >> $b_log ... (4 Replies)
Discussion started by: CAGIRL
4 Replies

9. AIX

How to find special characters??

By more, vi, cat etc commands special characters (few control characters) are not identified. Is there any way to find out those? Thanks Sumit (3 Replies)
Discussion started by: sumitc
3 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question