I have a datafile that is formatted as fixed.
I know that each line should contain 880 characters.
I want to separate the file into 2 files, one that has lines with 880 characters and the other file with everything else.
Is this possible ?
Yes,
please post a small representative sample of the input data and an example of the expected output.
Rather than 880 characters, perhaps simpler to see/explain with 8. So, if the following input file:
AAAAAAAA
BBBBBBBBBB
BBBBBBB
AAAAAAAA
AAAAAAAA
BBBBB
Thus, you want to create two files, selecting on if '8' characters. Therefore you will get file1 with the 3 A records all at 8 characters, and file2 with the 3 B records with lengths not 8 characters.
Is that correct?
example...any line that has 50 chars goes in one file, everything else goes in the other
HEADER
12345678901234567890123456789012345678901234567890
123456 John Doe 1 Main St asdw
789012 John Doe 22 Main St xcdf
345678 John Doe 1 Main St fgty
901234 John Doe 1 Main St gg
567890 John Doe 1 Main St dety
1122337 John Doe 1 Main St lgky
445566 John Doe 1 Main St oprd
778899 John Doe 1 Main St kgit
EOF
12345678901234567890123456789012345678901234567890
123456 John Doe 1 Main St asdw
345678 John Doe 1 Main St fgty
567890 John Doe 1 Main St dety
445566 John Doe 1 Main St oprd
HEADER
789012 John Doe 22 Main St xcdf
901234 John Doe 1 Main St gg
1122337 John Doe 1 Main St lgky
778899 John Doe 1 Main St kgit
EOF
---------- Post updated at 10:07 AM ---------- Previous update was at 10:06 AM ----------
joeyg...........you are correct
The basic premise is:
echo abcdef | awk 'length==6{print}'
abcdef
how do I pass in the contents of the datafile ?
awk '{if(length==50) print > "file1"; else print > "file2";}' data.txt
cat works to pass in the contents for this....
cat data.txt | awk 'length==19{print}'
how do I pass in the contents for this statement...?
{if (length() == 880)
print > "valid.file";
else
print > " invalid.file"
}
---------- Post updated at 05:37 PM ---------- Previous update was at 05:33 PM ----------
that works....thanks!
cat data.txt | awk 'length==19{print}'
You don't really need to do like this. Better way is:
awk 'length==19{print}' data.txt
Also look at my earlier post# 7. data.txt is highlighted there. Same as above.
works for me....thank you !