Removing bad records from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing bad records from a text file
# 1  
Old 02-24-2010
Removing bad records from a text file

Hi,

I have an requirement where i need to remove few bad records(bad records I mean email id's are part of the 1st field, where a numeric value expected) from the text file delimited by ",".

file1.txt
---------
1234,,DAVID,MAX
abc@email.com,,JOHN,SMITH
234,,ROBERT,SEN

I need to remove all the lines which contains "email address in the 1st field" from the file

Please help me out.

Thanks in advance.
# 2  
Old 02-24-2010
Code:
awk -F, '$1 !~ /@/' input_file

# 3  
Old 02-24-2010
Code:
 awk -F "," '{if ($1~/@/) {$1=""}}1' OFS=","  file1.txt



---------- Post updated at 07:14 PM ---------- Previous update was at 07:13 PM ----------

Quote:
Originally Posted by scottn
Code:
awk -F, '$1 !~ /@/' input_file

Mine is wrong, this is correct.
# 4  
Old 02-24-2010
Thanks Scott... it works fine....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete records based on a text file from a text file

Hi Folks, I am a novice and need to build a script in bash. I have 2 text files data.txt file is big file, column 2 is the we need to search and delete in the output. The filter file contains the rows to be deleted. Data.txt state city zone Alabama Huntsville 4 California SanDiego 3... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. Shell Programming and Scripting

Remove bad records from file and move them into a file then send those via email

Hi my requirement is that i want pull the bad records from input file and move those records in to a seperate file. that file has to be sent via email.. any suggentions please (1 Reply)
Discussion started by: sxk4999
1 Replies

3. Shell Programming and Scripting

remove bad records.

HI I have a problem in a file .The file was generated with the wrong data in it. MAL 005158UK473BBTICK1120722 A9999999ADASCD 1120722ADD_SECURIADD_SECURI MAL 005158UK473BBU 1120722 A9999999FF000EA0B9C 1120722ADD_SECURIADD_SECURI MAL 005158UK473ISN 1120722 A9999999US005158UK43... (5 Replies)
Discussion started by: ptappeta
5 Replies

4. Shell Programming and Scripting

Removing duplicate records in a file based on single column explanation

I was reading this thread. It looks like a simpler way to say this is to only keep uniq lines based on field or column 1. https://www.unix.com/shell-programming-scripting/165717-removing-duplicate-records-file-based-single-column.html Can someone explain this command please? How are there no... (5 Replies)
Discussion started by: cokedude
5 Replies

5. Shell Programming and Scripting

removing file with bad characters

I have the following files in the same directory but if you look at the od output you can see one of the files has and "\n" as part of the file name. Is there a way I can only remove the file with the "\n" as part of the file name without affecting the other file. I was thinking about... (4 Replies)
Discussion started by: BeefStu
4 Replies

6. Shell Programming and Scripting

Removing duplicate records in a file based on single column

Hi, I want to remove duplicate records including the first line based on column1. For example inputfile(filer.txt): ------------- 1,3000,5000 1,4000,6000 2,4000,600 2,5000,700 3,60000,4000 4,7000,7777 5,999,8888 expected output: ---------------- 3,60000,4000 4,7000,7777... (5 Replies)
Discussion started by: G.K.K
5 Replies

7. Shell Programming and Scripting

How to find Duplicate Records in a text file

Hi all pls help me by providing soln for my problem I'm having a text file which contains duplicate records . Example: abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 tas 3420 3562 ... (1 Reply)
Discussion started by: G.Aavudai
1 Replies

8. Shell Programming and Scripting

How to findDuplicate Records in a text file

Pls Any one help me in (2 Replies)
Discussion started by: G.Aavudai
2 Replies

9. UNIX for Advanced & Expert Users

Duplicate records from oracle to text file.

Hi, I want to fetch duplicate records from an external table to a text file. Pls suggest me. Thanks (1 Reply)
Discussion started by: shilendrajadon
1 Replies

10. Shell Programming and Scripting

problem with bad records

I have a data file with around 1 million records and i have 12 data fileds in each record seperated by 11 pipes. The file also has some bad records where there is only one pipe in some of the records. I want to print all this records with only one pipe in them. These bad records are broken... (4 Replies)
Discussion started by: dsravan
4 Replies
Login or Register to Ask a Question