Neeraj Neeraj - 1 year ago 95
Bash Question

In shell script, can I specify more than one output delimiter in cut?

I have a file with the following data


I need an output using command
as the following


I need to include both the delimiters
in my output using cut.

I've got the output with one delimiter using this code

cat file.txt |cut -c2-4,11-13,14-15,16-17,18-20 --output-delimiter='|'



Can I get 2 output delimiters by changing something in the command?

Answer Source

cut supports a single delimiter at a time, but you can easily replace this with a simple sed or Awk script.

awk '{ print substr($0, 2, 4) "|" substr($0, 11, 13) "."
   substr($0, 14, 15) "|" substr($0, 16, 17) "."
    substr($0,18, 20) }' file.txt

Coincidentally the cat is useless.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download