Unix Record Extract by Column Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jraymond
    New Member
    • Apr 2010
    • 2

    Unix Record Extract by Column Value

    I have a file of thousands of records. In column 87 it can contain 001, 002, 003, or 004. I need a quick easy way to create an output with all the records greater than 002. What unix command can do this? Or, do I need to write a quick program.
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    You do not write what is the column separator, assuming it is a ':' yo can do something like that
    Code:
    awk 'BEGIN{$IFS=":"}$87=!/00[1,2]/{print}' <filename>
    I guess saying grater than 002 you mean rows which do not contain 001and 002

    Comment

    • jraymond
      New Member
      • Apr 2010
      • 2

      #3
      There are no column separators just a string of alphanumeric data. Basically I have a datafile being transmitted to us and I neet to strip off certain records.

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        Originally posted by jraymond
        There are no column separators just a string of alphanumeric data. Basically I have a datafile being transmitted to us and I neet to strip off certain records.
        If there are no column separator, how do you recognize that 001 is in column 87?
        Can you put here some data from that datafile and show where do you think 87th column is.

        Comment

        • ennoil
          New Member
          • May 2010
          • 11

          #5
          You can use the cut (-b) command and specify what position in the string that you want to look at...From there you can use an if statement:

          Code:
          for i in `cat <file>`
          do
            section=`echo ${i} | cut -b 87-89`
            if [[ ${section} == "003" -o ${section} == "004"
            then
              echo ${section}
            fi
          done
          Just for a start...

          Comment

          Working...