nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Field Spiting Based Upon Digits

This is a discussion on Field Spiting Based Upon Digits within the Shell scripting forums, part of the Development/Scripting category; My input data: Code: 12345 Word1 word2 word3 word4 word5 12455345 Word1 word2 1565 Word1 word2 word3 How do I ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2009, 01:57 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Angry Field Spiting Based Upon Digits

My input data:
Code:
12345  Word1 word2 word3 word4 word5
12455345       Word1 word2
1565  Word1 word2 word3
How do I split data so end result will be like
f1=number
f2..Fn=Word1 word2 word3 word4 word5 WordN

Final output should be
HTML Code:
<tr><td>12345</td><td>Word1 word2 word3 word4 word5</td></td></tr>
Tried out awk but stuck at -F option:
Code:
awk -F'[0-9]+' '{ print "<td>"$1 "</td><td>"$2$3 }' file
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
  #2 (permalink)  
Old 02-07-2009, 02:11 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try replacing -F '[0-9]+' with -F '[:digit:]' class.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 02-07-2009, 06:23 PM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 78
Thanks: 0
Thanked 14 Times in 14 Posts
Rep Power: 2
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

Quote:
Originally Posted by rockdalinux View Post
My input data:
Code:
12345  Word1 word2 word3 word4 word5
12455345       Word1 word2
1565  Word1 word2 word3
How do I split data so end result will be like
f1=number
f2..Fn=Word1 word2 word3 word4 word5 WordN

Final output should be
HTML Code:
<tr><td>12345</td><td>Word1 word2 word3 word4 word5</td></td></tr>

Why are you trying to split on digits? That's not what you want.

In the shell:

Code:
while read f1 f2
do
  printf "<td>%s</td><td>%s</td>\n" "$f1" "$f2"
done < "$file"
Quote:
Tried out awk but stuck at -F option:
Code:
awk -F'[0-9]+' '{ print "<td>"$1 "</td><td>"$2$3 }' file

Code:
awk '{
 $1 = $1 "</td>"
 $2 = "<td>" $2
 printf "<td>%s</td>\n", $0
}' "$file"
But shouldn't it be:

Code:
awk '{
 $1 = $1 "</td>"
 $2 = "<td>" $2
 printf "<tr><td>%s</td></tr>\n", $0
}' "$file"
Reply With Quote
The Following User Says Thank You to cfajohnson For This Useful Post:
rockdalinux (02-07-2009)
  #4 (permalink)  
Old 02-07-2009, 07:59 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Thanks cfajohnson!
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply

Tags
awk , awk fs , field separator , scripting , sed


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Bandwidth limit based on MAC address kasimani Proxy Servers 0 02-05-2009 12:22 PM
Solaris Web based management, ZFS and Sun Cluster. Zepiroth Solaris/OpenSolaris 0 30-01-2009 09:32 AM
Apache multiple IP based domains and one certificate tom All about FreeBSD/OpenBSD/NetBSD 1 26-06-2006 07:23 PM
moving files based on size kavi Shell scripting 2 11-11-2005 05:17 PM
unable to cut required field 1 from this output ricc Shell scripting 3 19-08-2005 03:31 PM


All times are GMT +5.5. The time now is 06:58 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38