Find the answer to your Linux question:
Results 1 to 5 of 5
How can I separate ls value by comma ? I want to several is value like ls -t -g from -rwxrwxrwxrwx 1 ali 44343 Fep 18 2002 sea.csv to be ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    How can I seperat ls value by comma ?

    How can I separate ls value by comma ?
    I want to several is value like
    ls -t -g
    from
    -rwxrwxrwxrwx 1 ali 44343 Fep 18 2002 sea.csv
    to be like this
    -rwxrwxrwxrwx , 1 ali , 44343 , Fep ,18 , 2002 , sea.csv

    Is there any way to do this in Unix c shell?

  2. #2
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    I think sed should do it,

    if you run:
    Code:
    ls -t -g | sed 's/\s\+/,/g'
    Or:
    Code:
    ls -t -g | sed 's/ /,/g'
    This should replace whitespace with commas in the output.

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    ls -t -g | awk 'BEGIN{OFS=","}$1=$1'

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    Thank you but I need more ??!!!!

    is there any way to combine two or three column
    like all date in one column
    -rwxrwxrwxrwx , 1 ali , 44343 , Fep ,18 , 2002 , sea.csv
    I wont to be
    -rwxrwxrwxrwx , 1 ali , 44343 , Fep 18 2002 , sea.csv

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    There may be a neater way, but something like this should do it:

    Code:
    ls -t -g | awk 'BEGIN{OFS=","} {print $1,$2,$3,$4,$5" "$6" "$7,$8;}'
    You may need to move around the commas and spaces in the print command depending on the exact output on your system.

Posting Permissions

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