Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i need to search for a pattern in files for example the content of the file is below
3555005!K!00630000078!C!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!D!16042296!DUMMY!20090805235959!0!47001231000000!0!336344324!1!1!POST!USAGE!336344324!0!3555005!C!336344324!1!!!EUR!1!1!!I!3555005!S!00630000078!20090805172515!LF010300!
here i want to search for lines with !D! and the 7th field in the line is less than the system date, then i want to delet the line and save the file.
is that possible? please help.
thanks,
Vijay

If ! is your field separator, then the 7th field is 16042296. How do you get a date out of that? The 5th field is a date "20090805235959" and 60th field is a date "20090805172515". A !D! would appear to be the 32d field.
This question requires much more information. However, modifying your input file using today's date (20 Sep 2009) I created 3 entries:
3555005!K!00630000078!C!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!D!16042296!DUMMY!20090805235959!0!47001231000000!0!336344324!1!1!POST!USAGE!336344324!0!3555005!C!336344324!1!!!EUR!1!1!!I!3555005!S!00630000078!20090805172515!LF010300!
3555005!K!00630000078!C!20090920235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!X!16042296!DUMMY!20090805235959!0!47001231000000!0!336344324!1!1!POST!USAGE!336344324!0!3555005!C!336344324!1!!!EUR!1!1!!I!3555005!S!00630000078!20090805172515!LF010300!
3555005!K!00630000078!C!20090920235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!K!204042880166840!I!20090805235959!47001231000000!16042296!336344324!A!1!ENG!0!00630000078!NO!00630000078!3555005!D!16042296!DUMMY!20090805235959!0!47001231000000!0!336344324!1!1!POST!USAGE!336344324!0!3555005!C!336344324!1!!!EUR!1!1!!I!3555005!S!00630000078!20090805172515!LF010300!I then wrote this rough script:
#!/bin/ksh
function processLine {
print $line | while IFS='!' read f1 f2 f3 f4 f5 f6 f7 theRest
do
if [[ $f5 -lt $Today ]]
then
WriteIt=1
else
WriteIt=0
fi
done}
typeset -L8 f5Today=$(date +%Y%m%d)
exec 3< junk099.txt
while read -u3 line
do
if [[ $line == *"!D!"* ]]
then
processLine
else
WriteIt=1
fiif [[ $WriteIt -eq 0 ]]
then
print $line
fi
doneRunning this script against the modified input file on 20 Sep 2009, it output the line that contained no !D! and the line that had a !D! but an equal date. I'll let you figure out the rest.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |