![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ksh - comma seperate input | Mike_the_Man | Shell Programming and Scripting | 4 | 11-05-2008 02:44 AM |
| how to seperate space in a string | kittusri9 | Shell Programming and Scripting | 5 | 05-08-2008 06:43 AM |
| Seperate commands on the same line | bobk544 | Shell Programming and Scripting | 3 | 07-28-2007 05:14 PM |
| Need help to seperate data | getdpg | Shell Programming and Scripting | 4 | 08-30-2006 05:28 AM |
| /usr/lib on a seperate partition | progressdll | UNIX for Advanced & Expert Users | 4 | 12-21-2004 09:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Here's your sample data in a code block to remove ambiguity about spacing after fishing around in "view page source" in my browser. I also realigned it to what I guess your data really looks like. The fact of spacing matters more to awk than the amount of spacing anyhow, but everyone who posts here should be aware that alignment gets ruined by the VBcode->HTML conversion unless it's in a code block.
Code:
test01 --- abc-01 name1
abc-02 name2
abc-03 name3
test02 --- abc-20 name4
abc-21 name5
test03 --- abc-22 name6
abc-23 name7
This should do what you want, though it is untested code, and you shouldn't run it until you understand it. Code:
#!/usr/bin/awk
NF == 0 { next } # Skip empty lines
NF == 4 { tag = $1 } # Pick up the tag
{ print tag, $(NF - 1), $NF } # Print lines with data
![]() |
|
|||||
|
You know more than I do about awk - I would've come up with some convoluted mess to do that.
![]() I can tell what your code is doing, but I'm wondering, won't the two lines Code:
NF == 4 { tag = $1 } # Pick up the tag
{ print tag, $(NF - 1), $NF } # Print lines with data
Code:
test01 --- abc-01 name1 Code:
abc-02 name2
abc-03 name3
|
|
|||||
|
Quote:
|
|
|||||
|
When you're making a post to the forums, you should see some buttons above the textbox you type your message in. Look for a button with the # symbol on it to insert code. Read the help page for more on VB Code.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|