INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with AWK File Processing

Help with AWK File Processing

(OP)
Hi All,

I have an input file in linux with the following entries:

X:1,2,3,4
Y:5,6,7,8
...and so on

I require an output like below:

X:1
X:2
X:3
X:4
Y:5
Y:6
Y:7
Y:8

Could someone please provide a solution to this?

Regards,
Gaurav

RE: Help with AWK File Processing

Hi

Assuming there are no other colons ( : ) and commas ( , ) then the field delimiters :

CODE --> command line

master # awk -F '[:,]' '{for(i=2;i<=NF;i++)print$1":"$i}' /path/to/input
X:1
X:2
X:3
X:4
Y:5
Y:6
Y:7
Y:8 

Feherke.
feherke.ga

RE: Help with AWK File Processing

(OP)
Super! Worked like a charm. Thank you so much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close