Direct the invalid lines to a separate files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Direct the invalid lines to a separate files
# 15  
Old 10-14-2009
MySQL same login using AWK..?

Thanks for the perl code.

I have a small doubt in the code. It is not retrieving the lines which contains less than the specified number of delimiters. If a line contains more than the number, it is not retrieving the same.
In the below case, a line with 152 delimiters will not be returned?
Any patch for the issue ?

Can we apply the same login using AWK..

Thank you


Quote:
Originally Posted by skmdu
Code:
# cat a
H|2009-10-13
abcdefghijklmnop|lkjadsdlkjkj
a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
ERRORline is this|lmonp|asdfasdf
abcdefghijklmnop|ASDJASDFASDF
bcdefghijklmonpasdfasdf|asdflkjoiuqwe
T|4

# perl -e 'while (<>){ print unless (/^([^\|]*\|){150,}/); }' < a
H|2009-10-13
abcdefghijklmnop|lkjadsdlkjkj
ERRORline is this|lmonp|asdfasdf
abcdefghijklmnop|ASDJASDFASDF
bcdefghijklmonpasdfasdf|asdflkjoiuqwe
T|4

# 16  
Old 10-14-2009
Quote:
Originally Posted by anandapani
Skumdu,

Your guess is absolutely correct,

Given code catered my requrement.
However, I have attached a small sample file, but actual file is a pipe delimited file with approx 150 fileds.
My objetive is to identify the records which are not having 150 delimiters...

So Could you please modify your code for my actual file??

Thanks a lot for your great help

---------- Post updated at 01:20 PM ---------- Previous update was at 12:40 PM ----------

Can anybody help please
As you asked in you previous post, the perl code which I posted is to retrieve a row which are not having the minimum of 150 delimiter.

In my last post, execution of perl code didnt return a line which has 152 '|'. Is this what you expected? can you please clarify?

And you are saying "Its not retrieving the lines which contains less than the specified number of delimiters. If a line contains more than the number, it is not retrieving the same. " what does it mean? It prints nothing? Smilie

Showed in my last post it prints the line which has less than 150 | delimiters.
# 17  
Old 10-14-2009
MySQL am I clear ...

Skmdu,

Previously I could have requested like this.

I want to have all the records which are not having 150 delimters. I want to see the records with < or > 150 delimiters.

If possible i want to capture all such records in a reject_file.

Am i clear now?
Please let me know if I can provide any kind of clarifications

Cheers,


Quote:
Originally Posted by skmdu
As you asked in you previous post, the perl code which I posted is to retrieve a row which are not having the minimum of 150 delimiter.

In my last post, execution of perl code didnt return a line which has 152 '|'. Is this what you expected? can you please clarify?

And you are saying "Its not retrieving the lines which contains less than the specified number of delimiters. If a line contains more than the number, it is not retrieving the same. " what does it mean? It prints nothing? Smilie

Showed in my last post it prints the line which has less than 150 | delimiters.
# 18  
Old 10-14-2009
So as per your input, you want to retrieve the lines, which has < or > 150 | delimiters, not equal to 150. If am not wrong, this may help you.
Code:
# cat a
H|2009-10-13
abcdefghijklmnop|lkjadsdlkjkj
a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|
b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
ERRORline is this|lmonp|asdfasdf
ERRORline is this|lmonp|asdfasdf|sfsdf|sdfsdf
abcdefghijklmnop|ASDJASDFASDF
bcdefghijklmonpasdfasdf|asdflkjoiuqwe
T|4

In the above file, line which has number of 'a|' has totally 150 |.
The line which has number of 'b|' has totally 160 |.
so it should not retrieve a| line.

Code:
# perl -e 'while (<> ){ print if(/^([^\|]*\|){1,149}[^|]*$/ || /^([^\|]*\|){151,}/); }' < a
H|2009-10-13
abcdefghijklmnop|lkjadsdlkjkj
b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
ERRORline is this|lmonp|asdfasdf
ERRORline is this|lmonp|asdfasdf|sfsdf|sdfsdf
abcdefghijklmnop|ASDJASDFASDF
bcdefghijklmonpasdfasdf|asdflkjoiuqwe
T|4

# 19  
Old 10-14-2009
Code:
awk -F'|' 'NF != 152' in_file > reject_file

For 150 Field Separator(delimiter) you will have 152 fields.
# 20  
Old 10-14-2009
MySQL awk not accepting more than 99 fields

Awk fails to run if the NF > 99. gawk can be used in place, but my shell is not having that command. So I thought to do it with perl logic.
But in the given code, it retrieves all the rows with more than 150 delimiters. My intentition is to filter all the records those not having 150 delimiters.

Therefore, code has to filter recors not only with 151 limiters but also with 149 delimiters.


If I am not clear, please let me know.


Quote:
Originally Posted by danmero
Code:
awk -F'|' 'NF != 152' in_file > reject_file

For 150 Field Separator(delimiter) you will have 152 fields.
# 21  
Old 10-14-2009
Quote:
Originally Posted by anandapani
Awk fails to run if the NF > 99.
Yours , not my Smilie

Quote:
Originally Posted by anandapani
gawk can be used in place, but my shell is not having that command.
awk, gawk, nawk,mawk are stand-alone utility not builtin shell.
What OS you run?

Quote:
Originally Posted by anandapani
So I thought to do it with perl logic.
If works for you why not.

Warning on Forum Rules (10) Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: output lines with common field to separate files

Hi, A beginner one. my input.tab (tab-separated): h1 h2 h3 h4 h5 item1 grpA 2 3 customer1 item2 grpB 4 6 customer1 item3 grpA 5 9 customer1 item4 grpA 0 0 customer2 item5 grpA 9 1 customer2 objective: output a file for each customer ($5) with the item number ($1) only if $2 matches... (2 Replies)
Discussion started by: beca123456
2 Replies

2. Shell Programming and Scripting

For loop in bash - Direct output to two files

Hello all, i have a code in which when doing a for loop, i need to direct the output to two files, one just a single output, the other to always append (historical reasons). So far i managed to do the following, which is working, but am still considering it as "dirty". ... (4 Replies)
Discussion started by: nms
4 Replies

3. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

4. Shell Programming and Scripting

how to write on separate lines?

Hello friends, I have a file "a.txt" its contents ----------------- pid 4075 (caiopr) shmat(1929379932, 0x0000000000000000, 0) = 0x00000000ff030000 (errno 0) pid 4075 (caiopr) shmdt(0x00000000ff030000) = 144 (errno 0) pid 4075 (caiopr) shmctl(1929379932, IPC_RMID) pid 4205 (cau9cli.exe)... (2 Replies)
Discussion started by: Sunusernewbie
2 Replies

5. Shell Programming and Scripting

loop through lines and save into separate files

I have two files: file-gene_families.txt that contains 30,000 rows of 30 columns. Column 1 is the ID column and contains the Col1 Col2 Col3 ... One gene-encoded CBPs ABC 111 ... One gene-encoded CBPs ABC 222 ... One gene-encoded CBPs ABC 212 ... Two gene encoded CBPs EFC... (7 Replies)
Discussion started by: yifangt
7 Replies

6. Shell Programming and Scripting

Combine the lines from separate text files

Hi All, I have three separate text files which has only one line and i want to combine these lines in one text file which will have three lines. cat file1.txt abc cat file2.txt 1265 6589 1367 cat file3.txt 0.98 0.36 0.5 So, I want to see these three lines in the... (9 Replies)
Discussion started by: senayasma
9 Replies

7. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

8. Shell Programming and Scripting

Concatenating lines of separate files using awk or sed

For example: File 1: abc def ghi jkl mno pqr File 2: stu vwx yza bcd efg hij klm nop qrs I want the reult to be: abc def ghistu vwx yza jkl mno pqrbcd efg hij klm nop qrs (4 Replies)
Discussion started by: tamahomekarasu
4 Replies

9. UNIX for Dummies Questions & Answers

download files from direct links tool?

Hello all I wander of there is small utility that gives me the possibility to download direct links to specific folder say if i have http://www.blah.com/foo.java and I like to download the foo.java without opening the browser and such... (2 Replies)
Discussion started by: umen
2 Replies

10. Programming

direct transmission of files via TCP/IP

Hi, is it possible to write files via write() to a socket and read it on the other side via read(), without going through buffers? Iif not via write() and read() are there other possibilities? thanks darkspace (5 Replies)
Discussion started by: darkspace
5 Replies
Login or Register to Ask a Question