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:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old January 18th, 2004, 05:44 PM
chess chess is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 chess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sed command in Unix

I want to get a bin number from one file and change the bin details of the bin in a different file. I wrote the following script but it doesn't seem to work.
#!/bin/sh

i=1

cat bin_size_changes.txt | while read LINE
do
BIN=`echo ${LINE} | awk '{print $1}'`
SIZE=`echo ${LINE} | awk '{print $3}'`
grep ${BIN} bin.dump | sed -n
's/"|${BIN}|[A-Z]*|"/"|${BIN}|${SIZE}|"/'
echo $LINE $i
echo $BIN
i=`expr $i + 1`
done

I believe there is somethign wrong in the sed command. Can any one help me with this pls.

Reply With Quote
  #2  
Old January 18th, 2004, 08:53 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
I have no idea of what your data looks like. Nor what you are trying to do. I don't even know what the heck a "bin" number is supposed to be.

Your sed command looks pretty bad. It's not clear what effect you're trying achieve, so I can't tell you how to fix it. But here are 2 comments that may help.

sed -n means don't print anything unless explicitly told to. You're not explicitly telling sed to print anything, so it won't. One way tio do that is to use a p flag on your substitute command. So
sed -n 's/cat/dog/p'
will change cat to dog then print the result.

Next, you can't put shell variables inside single quotes.
THIS=cat
THAT=dog
sed -n 's/${THIS}/${THAT}/p'
won't work. You could use double quotes. Or you could break the singles to expose the variables:
sed -n 's/'${THIS}'/'${THAT}'/p'

Reply With Quote
  #3  
Old January 19th, 2004, 12:58 AM
chess chess is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 chess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I tried your code but it doesn't seem to work though. The data in the file is set out like this

|234|0||23 Jun||BIN NUMBER|SIZE OF BIN|

I have a set of bin numbers in a file. All I want to do is to get the line of data containing the Bin number and change the size to a different size. I would be glad if you could help me in this regard.

Reply With Quote
  #4  
Old January 19th, 2004, 01:41 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Try:

sed 's/|'${BIN}'|.*/|'${BIN}'|'${SIZE}'|/'

Reply With Quote
  #5  
Old January 19th, 2004, 06:28 PM
chess chess is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 chess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx mate it worked. Infact i had the pattern wrong too. appreciate the help but can you pls tell me how i can put the output of this script into a file. just the out put of the following sed command.
grep ${BIN} bin.dump | sed 's/|'${BIN}'|.*]/|'${BIN}'|'${SIZE}']/'

Reply With Quote
  #6  
Old January 19th, 2004, 07:40 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
grep ${BIN} bin.dump | sed 's/|'${BIN}'|.*]/|'${BIN}'|'${SIZE}']/' > somefile

Reply With Quote
  #7  
Old January 19th, 2004, 10:17 PM
chess chess is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 chess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

Sorry I should have mentioned it before. I have already tried that thing and it doesn't work, nothing gets into the file.

Reply With Quote
  #8  
Old January 20th, 2004, 05:37 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Beats me then. That shoulda worked.

Reply With Quote
  #9  
Old January 20th, 2004, 08:24 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
Upon further review...

I have an idea. I read your last question too literally. You are invoking that command in a loop. Each iteration of the loop redefines the contents of the output file. That's true even if there are no lines found by the grep.

Try using:
>> somefile

This way each iteration adds to the file.

Reply With Quote
  #10  
Old January 20th, 2004, 11:12 PM
chess chess is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 chess User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

It worked... Thanx mate that was a greate help, really appreciate it and now I know why the > didn't work too...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sed command in Unix


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 2 hosted by Hostway