UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 1st, 2005, 03:29 AM
masa567 masa567 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 7 masa567 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 39 sec
Reputation Power: 0
Question UNIX sed (please help!!)

I have a sed problem. Is threre a way to transform rows like:

column Condition int

into:

column Condition
{
type = int;
description = "" +
"" +
"" +;
};

So need to transform 1 line to multiple lines. There should be \t -character in front of 'type' and 2 \t-characters in front of "" -rows.

Thank you

PS. If there is other UNIX program that makes it easier. Please tell and give the example.

Last edited by masa567 : December 1st, 2005 at 05:56 AM. Reason: Maybe sed is not best

Reply With Quote
  #2  
Old December 11th, 2005, 11:01 PM
bingotailspin's Avatar
bingotailspin bingotailspin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 118 bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level)bingotailspin User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 12 h 18 m 52 sec
Reputation Power: 7
Take it a line at a time, use cut

Quote:
grep ^ file
will give you one line at a time.

Quote:
for line in `grep ^ file`;do
col=`echo $line |cut -d' ' -f1`
cond=`echo $line |cut -d' ' -f2`
intval=`echo $line |cut -d' ' -f3`
echo "Whatever you want interspersed with variables ${col} ${cond} ${intval}"
done

Reply With Quote
  #3  
Old December 15th, 2005, 02:29 PM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by masa567
I have a sed problem. Is threre a way to transform rows like:

column Condition int

into:

column Condition
{
type = int;
description = "" +
"" +
"" +;
};

So need to transform 1 line to multiple lines. There should be \t -character in front of 'type' and 2 \t-characters in front of "" -rows.

Thank you

PS. If there is other UNIX program that makes it easier. Please tell and give the example.



Hello,

I think the awk is better for this purpose. Try this:

:
awk '
NF == 3 {
printf "%s %s\n", $1, $2
printf "{\n\ttype %s;\n", $3
printf "descritpiom = \"\" +\n"
printf "\t\t \"\" +\n"
printf "\t\t \"\" +;\n"
printf "};\n"
}
' <<EOF
column condition int
a b c
EOF

If you are on Solaris, put nawk instead of awk. This script transforms only the lines with exactly three fields separated by one or more white spaces. Ohter lines are silently ingnored. This is only to demonstrate the basic idea, you can add error messages for bad lines etc.

I have used here the 'here document', you will input your data from the file, of course. Should you have any problems write again.

Tested on Fedora Linux

Regards zlutovsky

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > UNIX sed (please help!!)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT