Computing.Net > Forums > Programming > Unix help- sed or awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix help- sed or awk

Reply to Message Icon

Name: pratyusha
Date: July 5, 2009 at 21:07:23 Pacific
OS: Linux
Subcategory: General
Comment:

I have a file of the following format.

2,
212.1.1.1
213.2.2.2 0.0.0.32
8,
10.1.2.3
172.4.5.212
172.212.212.212

The output should be as shown below. So, Whereever, there is a comma in a line, the line contents should be prefixed to the next few lines until the the next line with comma is seen.

2 212.1.1.1
2 213.2.2.2 0.0.0.32
8 10.1.2.3
8 172.4.5.212
8 172.212.212.212



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 5, 2009 at 21:41:51 Pacific
Reply:

awk -F"," '/,$/{s=$1;next}{ print s,$0}' file

GNU win32 packages | Gawk


0

Response Number 2
Name: pratyusha
Date: July 6, 2009 at 12:23:45 Pacific
Reply:

Thank you. That worked.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Unix help- sed or awk

vb6 help HTML Remove www.computing.net/answers/programming/vb6-help-html-remove/7120.html

reformat file, Script Help -- Perl or Awk?? www.computing.net/answers/programming/reformat-file-script-help-perl-or-awk/20271.html

put text between 2 lines www.computing.net/answers/programming/put-text-between-2-lines/12559.html