Control Characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Control Characters
# 8  
Old 06-29-2011
Hello Sir..

Wel i have a file called mireport.txt

which has values like this ( below is one row records)

"4208"|"INCIDENT"|"BaNCS Accurate file issues in LCT"|"RESOLVED"|"2011-06-10-12.19.08.563000"|2|2|2|"174021"|"2011-05-25-12.17.54.533000"|"174021"|"2011-05-25-12.17.54.000000"|||"BANCS"|||"2011-05-25-12.47.54.533000"|"2011-05-25-20.17.54.533000"|"2011-06-09-14.18.44.324000"|"2011-06-10-12.19.08.563000"|"BGL"|"NEST"|"2011-06-22-14.42.28.179000"|"253563"|"1025"||1||"174021"|"2011-05-25-12.17.54.533000"|"APP_SERVICES"|"BANCS"

I will be loading this to my data base.. before loading , my manager asked me2 check if it has control characters or not.. if it has i should not take this file for loading , displaying error msg saying it has control character..!!

I have written other part of code, but i want a part of code in unix, which will check if the file ( i have other files too) has control character or not.. based upon that display msg..

Please help me with the same.
# 9  
Old 06-29-2011
If your grep supports extended regular expressions you can do something like this:

Code:
if grep -qE '[[:cntrl:]]' your_file
then
    echo Cannot process: File contains control characters!
    exit 1
fi

# 10  
Old 06-29-2011
Quote:
Originally Posted by Chubler_XL
If your grep supports extended regular expressions you can do something like this:

Code:
if grep -qE '[[:cntrl:]]' your_file
then
    echo Cannot process: File contains control characters!
    exit 1
fi


What Chubler_XL said is right.

Additionally you can redirect the output to logfile with timestamp.
# 11  
Old 06-29-2011
Is this a standard unix text file with each line terminated with a linefeed character? If so, linefeeds will match the Regular Expression [[:ctrl:]] .
# 12  
Old 06-29-2011
Hi methyl,

My Os version is SunOS 5.9.

However, the script is not working:
Error:
Code:
grep: illegal option --  q
 grep: illegal option --  E
 Usage: grep -hblcnsviw  pattern file . . .

Any suggestion?
# 13  
Old 06-29-2011
Try /usr/xpg4/bin/grep instead of grep

Jean-Pierre.
# 14  
Old 06-30-2011
Quote:
Originally Posted by aigles
Try /usr/xpg4/bin/grep instead of grep

Jean-Pierre.
Hi Jean,

I tried the above code in UAT server...

OS Version:
Code:
ksh:0$ uname -a
SunOS 5.9 Generic_122300-48 sun4u sparc SUNW,Sun-Fire-V440

My code is:
Code:
#! /bin/ksh
 
if /usr/xpg4/bin/grep -qE '[[:cntrl:]]' control_char_file.dat
then
    echo 'Cannot process: File contains control characters!'
    exit 1
else
    echo 'No control characters found!!!'
fi

The input file is:
Code:
F|852871
F|852872^M
- Saps.

I'm getting error like:
Code:
ksh:0$ ksh test_control_char.ksh
test_control_char.ksh[11]: usr/xpg4/bin/grep:  not found
No control characters found!!!

Permission of both files: -rwxr--r--

Please help.

Working fine now... Smilie

---------- Post updated 06-30-11 at 05:33 AM ---------- Previous update was 06-29-11 at 10:20 AM ----------

Hi @Alister,

1. Can we use
Quote:
[:cntrl:] character class
in perl script?

2. We have a dos2unix validation in our perl script which will get the following command from DB using SELECT query:
Code:
dos2unix -437 -q <some_file_nm>

-437 is for Key Board format message.
What will '-q' do?

Last edited by saps19; 06-29-2011 at 01:36 PM.. Reason: modification in script. missed '/' before usr/xpg4/bin/grep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control Characters

Hallo Team, I am trying to get rid of the dollar sign. I managed to remove all the other special characters but i am struggling with this one. -bash-3.2$ cat -e missing_revenue_20141112.csv|less|head BW0522168531211141180935668@196.23.110.141$ BW092218784121114-370120610@196.23.110.141$... (4 Replies)
Discussion started by: kekanap
4 Replies

2. UNIX for Dummies Questions & Answers

Control characters in UNIX

Hi, My files are showing some control characters in vi editor ^M ^@ and somtimes ^H I removed ^M with %s/^M//g command but how to represent ^@ and ^H e.g. for ^M it is hold ctrl then v and m.. Please help.. I am very new to unix.. (7 Replies)
Discussion started by: prabhat.diwaker
7 Replies

3. Shell Programming and Scripting

Control characters -weird problem

I am using Korn shell on Linux 2.6x platform , and I am suing the following code to capture the lines which contain CONTROL CHARACTERS in my file : awk '/]/ {print NR}' EROLLMENT_INPUT.txt The problem is that this code shows the file has control characters when the file is in folder A ,... (2 Replies)
Discussion started by: kumarjt
2 Replies

4. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

5. Shell Programming and Scripting

Urgent : Control Characters

Can somebody please help me with the query. ? I want a part of program of which should look for control characters in the flat file , when it finds it, displaying message that Control Characters found..! Please help me (1 Reply)
Discussion started by: iamnoone
1 Replies

6. Shell Programming and Scripting

screen control characters

Hi, Can anyone help me with controlling the cursor position from a shell script. Things like moving left,right,up,down etc Anyone have any ideas? (2 Replies)
Discussion started by: ajcannon
2 Replies

7. Shell Programming and Scripting

how to replace control characters using sed?

How can I use sed to replace a ctrl character such as 'new line' (\0a) to something else? Or any other good command can do this job? Thanks, Hillxy (5 Replies)
Discussion started by: hillxy
5 Replies

8. UNIX for Dummies Questions & Answers

Remove control characters

Hi, When I do a man and save it into a file, I end up getting a lot of control characters. How can I remove them?? I tried this: /1,$ s/^H//g But I get an error saying "no previous regular expression". Can someone help me with this. Thanks, Aravind (5 Replies)
Discussion started by: aravind_mg
5 Replies

9. UNIX for Dummies Questions & Answers

getting rid of control characters

how can i get rid of the control characters , ex. ^M, ^G, in a file? thanks... (2 Replies)
Discussion started by: apalex
2 Replies

10. UNIX for Dummies Questions & Answers

printing control characters

using c-shell, does anyone know how to send control characters to the printer before the job? I need to set a printer to print in condensed mode HELP (1 Reply)
Discussion started by: mglinsk
1 Replies
Login or Register to Ask a Question