Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What to use (awk, sed, etc)? 3

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
Hello all...
I have a question that might be pretty simple. I have a fixed-length file that has 30 bytes per record. The 30th byte is a flag with a value of 'Y' or 'N'. This would be extremely easy is this was in a relation database, but since it isn't, I was wondering if anyone had any ideas of how I could write out, into a new file, just the records where that 30th byte = 'Y'. So, if my file looks like this:

12345678901234567890123456789Y
12345678901234567890123456789N
12345678901234567890123456789Y
12345678901234567890123456789N

I want output like this:

12345678901234567890123456789Y
12345678901234567890123456789Y

I just want to create a new file that contains only the first and third record (where 30th byte = 'Y'), you know?
Any help would be greatly, greatly appreciated. Thanks!
 
more filename |grep Y > newfile



[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
sorry, CAT filename |grep Y > newfile



[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
The char to test is the last of each line, so i prefer :

grep 'Y*' filename > newfile

Jean Pierre.
 
grep! Now why didn't I think of that! Thanks to you both. Next time I have a brain fart, I'll know where to turn!
 
Considering the 30th byte requirement....... (on Sun/Solaris):

/usr/xpg4/bin/grep -e '^.\{29\}Y.*' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Oups, my previous post is badly typed :

grep 'Y$' filename > newfile

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top