4 Replies Latest reply: Feb 10, 2014 10:38 AM by Tommyreynolds-Oracle RSS

    need to have cut command!

    446

      Hi.. Here i need to cut 2013.11.0,2.3.1,2.0.0,1.0 alone and need to put it in a text file using cut commands

       

       

      <A4Client>rd-ec-fulfill-2013.11.0</A4Client>

      <A4Client>rd-apra-pur-dom-2.3.1</A4Client>

      <A4Client>rd-c3-aip-web-adm-2.0.0</A4Client>

      <A4Client>rd-c3-fb-vb-fb-vb-1.0-POC</A4Client>

       

       

      Here i use to get these stuff from a logfile using while loop,so i need a probably cut command which should satisfy all the scenarios

        • 1. Re: need to have cut command!
          Catch~22

          Unless there is any kind of logic or format, which is not obvious, you may have to extract each field using the dash (hyphen character) as a delimiter and check for alphanumeric content.

          • 2. Re: need to have cut command!
            446

            Thanks Dude-  i have an idea to design a cut command based on the count of "-",while framing using expr am getting erro-

             

            in the variable b=`echo $i|grep -o"-"|wc -l'  - storig the count of hyphen character..

             

              using c=`echo $i|cut -d"-" -f$(expr$c+1)|cut -d"/" -f1|cut -d"<" -f1` while trying to store the desired value ..am getting the following err -

             

            Try `cut --help' for more information.

            ./test.sh[17]: expr7+1: not found [No such file or directory]

            cut: option requires an argument -- 'f'

            • 3. Re: need to have cut command!
              Catch~22

              Perhaps it will be much easier to do the following:

               

              $ cat infile.txt

              <A4Client>rd-ec-fulfill-2013.11.0</A4Client>

              <A4Client>rd-apra-pur-dom-2.3.1</A4Client>

              <A4Client>rd-c3-aip-web-adm-2.0.0</A4Client>

              <A4Client>rd-c3-fb-vb-fb-vb-1.0-POC</A4Client>

               

              $ cat script1

              #!/bin/bash

              #

              while read line; do

                 line=${line#<A4Client>}

                 line=${line%</A4Client>}

                 line=$(echo $line | tr "-" "\n")

                 for item in $line; do

                    echo $item | grep '\.'

                 done

              done < infile.txt > outfile.txt


              $ ./script1


              $ cat outfile.txt

              2013.11.0

              2.3.1

              2.0.0

              1.0

              • 4. Re: need to have cut command!
                Tommyreynolds-Oracle

                Here is a case for using a regular expression.  Put these lines in a file:


                #!/bin/awk -f
                {
                    if( match( $0, /([0-9]{1,}\.[0-9\.]*)/ ) > 0 )    {
                        print substr( $0, RSTART, RLENGTH ) | "sort -n"
                    }
                }


                and make it executable.  Run it like this:


                $ ./howto data

                1.0

                2.0.0

                2.3.1

                3.11.0


                OK, I cheated by having awk(1) pipe the output directly through sort(1); leave that out if you do not need that feature.