1

Hi I have the following text and I need to use awk or sed to print 3 separate columns

11/13/14    101 HUDSON AUBONPAINJERSEY CITY NJ      $4.15
11/22/14    MTAMVM*110TH ST/CATNEW YORK NY          $19.05
11/22/14    DUANE READE #14226 0NEW YORK NY         $1.26

So I like to produce a file containing all the dates. Another file containing all the description and third file containing all the numbers

I can use an awk to print the first column printy $1 and then use -F [$] option to print last column but I'm not able to just print the middle column as there are spaces etc. Can I ignore the spaces? or is there a better way of doing this?

Thaking you in advance

2 Answers 2

5

Try doing this :

 $ awk '
     {
         print $1 > "dates"; $1=""
         print $NF > "prices"; $NF=""
         print $0 > "desc"
     }
' file

or :

awk -F'  +' '
    {
        print $1 > "dates"
        print $2 > "desc"
        print $3 > "prices"
    }
' file 

Then :

$ cat dates
$ cat desc
$ cat prices
Sign up to request clarification or add additional context in comments.

1 Comment

Added another awk solution
0

Wasn't fast enough to be the first to give an awk solution, so here's one with grep and sed...

grep -o '^.*/.*/1.' file   #first col
sed 's/^.*\/.*\/1.//;s/\$.*//' file   #middle col
grep -o '\$.*$' file    #last col

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.