ignore fields to check in grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ignore fields to check in grep
# 1  
Old 07-05-2010
ignore fields to check in grep

Hi,

I have a pipe delimited file. I am checking for junk characters ( non printable characters and unicode values).
I am using the following code
Code:
grep '[^ -~]' file.txt

But i want to ignore the name fields. For example field2 is firstname so i want to ignore if the junk characters occur there and not consider it as a bad record.

Also, I want to process the file at once and not line by line in a loop. Thats why i was using hte above command.

---------- Post updated at 03:02 AM ---------- Previous update was at 02:13 AM ----------

Any help??
# 2  
Old 07-05-2010
may be..

Code:
awk -F "|" '$1 ~ /[^ -~]/ || $3 ~ /[^ -~]/ || $4 ~ /[^ -~]/ {print}' file

# 3  
Old 07-05-2010
I have around 150 columns.. It might not look so good.. instead is there any way to do it the other way round.. check for not equal to..

Is there a way to ignore 2 fields and check for rest of the fields.I am not able to achieve that in a single go, by reading the file in one shot.
# 4  
Old 07-05-2010
Code:
awk -F "|" '{for(i=1;i<=150;i++) {if(i != 2 && $i ~ /[^ -~]/) {print}}}' file | sort -u

If you want detailed info about the matches, you can do something like this:
Code:
awk -F "|" '{for(i=1;i<=6;i++) {if(i != 2 && $i ~ /[^ -~]/) {print "found in field "i": "$0}}}' file

There could also many other ways.
# 5  
Old 07-07-2010
The command below will look for all control characters and unicode characters.Is it correct.
Code:
grep '[^ -~]' file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep and ignore list from file

cat /tmp/i.txt '(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)' grep -ia 'ORA-\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt` grep: Unmatched ( or \( Please tell me why am i getting that (6 Replies)
Discussion started by: jhonnyrip
6 Replies

2. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

3. UNIX for Dummies Questions & Answers

Does rsync check and ignore files that already exist?

Hi, We have two (2) servers named primary and standby. There is a directory named /db01/archive that we need to keep in-sync. Files get transferred from primary and standby. Sometimes when we do a failover or when there is a network issue, some files fail to get transferred. I want to use... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. Shell Programming and Scripting

Grep command to ignore line starting with hyphen

Hi, I want to read a file line by line and exclude the lines that are beginning with special characters. The below code is working fine except when the line starts with hyphen (-) in the file. for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'` do . . done How... (4 Replies)
Discussion started by: Srinraj Rao
4 Replies

5. Shell Programming and Scripting

Grep regex to ignore sequence only if surrounded by fwd-slashes

Hi, I've got a regex match to perform in a Bash script and can't quite get it right. Basically I want to match all IP address like sequences in a file which may or may not contain an IP address but with the extra qualification of ignoring any IP-like sequence which begins and ends with a... (27 Replies)
Discussion started by: gencon
27 Replies

6. Shell Programming and Scripting

awk print - fields separated with comma's need to ignore inbetween double quotes

I am trying to re-format a .csv file using awk. I have 6 fields in the .csv file. Some of the fields are enclosed in double quotes and contain comma's inside the quotes. awk is breaking this into multiple fields. Sample lines from the .csv file: Device Name,Personnel,Date,Solution... (1 Reply)
Discussion started by: jxrst
1 Replies

7. Shell Programming and Scripting

Grep but ignore first column

Hi, I need to perform a grep from a file, but ignore any results from the first column. For simplicity I have changed the actual data, but for arguments sake, I have a file that reads: MONACO Monaco ASMonaco MANUTD ManUtd ManchesterUnited NEWCAS NewcastleUnited NAC000 NAC ... (5 Replies)
Discussion started by: danhodges99
5 Replies

8. Shell Programming and Scripting

Check numeric fields greater than zero, and delete lines if appropriate

This be the latest in my problems sorting through router logs... I'm half way there on a problem, but I've hit the limitation of my knowledge Got some router interface log files of type router01:GigabitEthernet9/24 is up, line protocol is up (connected) router01: 0 input errors, 0 CRC, 0... (7 Replies)
Discussion started by: Yorkie99
7 Replies

9. Shell Programming and Scripting

How to grep more than 2 fields?

Hi all, Currently I have this: ps -eo pid,comm| grep CSORDB1T But I need to grep LOCAL=NO as well: ps -eo pid,comm| grep CSORDB1T |grep LOCAL=NO >pdwh_pid However, there's no output. Plz advise how can we grep CSORDB1T & LOCAL=NO at the same time. Thanks! (8 Replies)
Discussion started by: *Jess*
8 Replies

10. Shell Programming and Scripting

How can you grep for three fields

I have data, from which I want to grep for two fields. Only pull out the data if both the fields exist. I have used: egrep --text "field1|field2" file > temp. This seems to be doing an OR. What I am after is an AND. (10 Replies)
Discussion started by: gugs
10 Replies
Login or Register to Ask a Question