Home » questions » How can i do this in unix?? i have to edit a file wthout using vi.?

How can i do this in unix?? i have to edit a file wthout using vi.?

2006-08-16 10:34:14, Category: Programming & Design
I have a file with the following structure: H|123450|1203|dsf5|trtr H|123949|4940|erjvh|hdhgd H|01-JAN-06|2398|jk55k|gdfbn H|120983|3894|sdfklj|fsdkf H|29-DEC-06|2398|lsdfj7|sflkj H|934806|2304|reoi5|sljks The file is in pipe delimited format as shown above. It is huge and cannot use vi, I have to delete the records which have the date format in the second field(01-JAN-06). How can i do this without using vi? any sed commands for this??

Answers

  1. Ken H

    On 2006-08-16 11:22:11


    If the second field is the only one with dates, a simple grep -v '|01-JAN-06|' yourfile > newfile should do it. You might need \| in place of | in that command, I can never remember until I try it.
  2. ouksta

    On 2006-08-16 10:48:50


    I would use awk, there's a tutorial here: http://www.vectorsite.net/tsawk.html example code would be: awk -F'|' '$2 ~ /^[0-9]+$/' test.txt > test2.txt
  3. rob

    On 2006-08-16 10:43:13


    can you copy it to a local machine, make the changes in a text editor and upload the new file?