0

I have a file (called customers) with information that needs to be sorted; example:

qweasd,asdqwd@asd.org,256.62394383
qweasdczasd,asdghjghqwd@assssd.org,256.62394383
qwedddasd,asdasdaqwd@asd.org,256.62394383
qweavvvdsd,asaaadqwd@asccd.org,256.62394383

Output of the file must be tab-separated.

qweasd         asdqwd@asd.org              256.62394383
qweasdczasd    asdghjghqwd@assssd.org      256.62394383
qwedddasd      asdasdaqwd@asd.org          256.62394383
qweavvvdsd     asaaadqwd@asccd.org         256.62394383

I need the command in one line.

  • 3
    How is the output sorted any differently than the input? If that's your most difficult automation task for the day, please consider accepting my resume for review. – mikeserv Jun 4 '15 at 7:13
  • Is that not just tr , '\t' < file you need? What has that to do with sorting or awk? – Stéphane Chazelas Jun 21 '15 at 7:39
  • @StéphaneChazelas: To be fair, the OP never mentioned awk.  The /awk tag was added by the person who submitted the first answer (which features awk). – G-Man Says 'Reinstate Monica' Jul 1 '15 at 21:35
  • @G-Man, indeed, that's a bit cheeky. awk is a poor choice here as an answer let alone a tag for the question, I don't understand why that was approved. The whole Q&A is poorly worded and unlikely to be useful to anyone anyway, no need to lose sleep over it. – Stéphane Chazelas Jul 1 '15 at 21:55
  • @StéphaneChazelas: As it happens, I voted to reject the edit, but I got outvoted. – G-Man Says 'Reinstate Monica' Jul 1 '15 at 22:08
1

You can use awk commands:

# awk -F, '{print $1 "\t" $2 "\t" $3}' customers

or :

# awk 'BEGIN{FS=","; OFS="\t"} {print $1, $2, $3}' customers

or :

# awk 'BEGIN{FS=","; OFS="\t"} {print}' customers

all of them will work for you.

| improve this answer | |
0

Try this: awk -F, '{print $1 "\t" $2 "\t" $3}' filename awk 'BEGIN{FS=","; OFS="\t"} {print $1, $2, $3}' filename

| improve this answer | |
0

sed is the more simple and efficient tool for this editor grade modification:

sed 's-,-ctrlVtab-g' customers

You can also very easily achieve the same modification with ex, vi or emacs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy