Find the answer to your Linux question:
Results 1 to 7 of 7
Hello friends, I hav the file data1 which contains the following data 2002,12,25,12345 i tried the following command for a single column cut -f2 -d',' data1 | paste - data1 ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    6

    help with cut paste

    Hello friends,
    I hav the file data1 which contains the following data
    2002,12,25,12345

    i tried the following command for a single column
    cut -f2 -d',' data1 | paste - data1

    But the result wat am getting is
    12,2002,12,25,12345

    I need the above file to be rearranged in the order shown below
    25,12,2002,12345

    Since i am new in scripting, I request someone to help me
    Thank you

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    (IFS=,;set -- $(<data1);printf "&#37;s,%s,%s,%s\n" "$3" "$2" "$1" "$4")

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    If you want a simple bash one too, you could do:

    Code:
    cat file | awk -F, '{print $3, $2, $1, $4}'

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by papetova View Post
    If you want a simple bash one too, you could do:

    Code:
    cat file | awk -F, '{print $3, $2, $1, $4}'
    you can skin the cat
    Code:
    awk -F, '{print $3, $2, $1, $4}' file

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    The OP expects a comma as field separator:

    Code:
    awk -F, '{print $3 "," $2 "," $1 "," $4}' file
    Regards

  6. #6
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    then try this:
    Code:
    awk 'BEGIN{OFS=FS=","}{print $3,$2,$1,$4}' "file"

  7. #7
    Just Joined!
    Join Date
    Oct 2007
    Posts
    6
    Quote Originally Posted by ghostdog74 View Post
    then try this:
    Code:
    awk 'BEGIN{OFS=FS=","}{print $3,$2,$1,$4}' "file"
    That worked gud thanx friends!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...