The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Appending data into a variable michaeltravisuk Shell Programming and Scripting 5 01-31-2009 04:20 AM
how to read the data from an excel sheet and use those data as variable in the unix c Anne Grace UNIX for Advanced & Expert Users 1 03-03-2008 07:21 AM
how to assign sql output data to shell script variable kattics Shell Programming and Scripting 1 07-07-2006 04:57 PM
Capturing some data from a file into a variable shiroh_1982 UNIX for Dummies Questions & Answers 11 06-16-2006 09:16 AM
Read data from a file into a variable yorkdg Shell Programming and Scripting 2 12-09-2004 05:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-01-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
Manipulating data in variable

Hi,

I have two variables - A and B - containing a bunch of file paths. I am comparing them and when I find a match I want to remove that entry from A so that as the compare proceeds A shrinks entry by entry.

How can I remove a matched entry from A whilst leaving the non matched entries intact?

Any ideas would be most welcome - apologies if this is dead easy - I am back in scripting after a *very* long time out..........
  #2 (permalink)  
Old 08-01-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
A sample value of A (or B for that matter) would help....
  #3 (permalink)  
Old 08-01-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
mA="3 2 4 5 7 9 33 66"
mB="3 6 7 8 9 0 22"
mAOut=${mA}
for mEach in ${mB}
do
   mAOut=`echo ${mAOut} | sed "s/\<${mEach}\>/ /"`
done
echo "mAOut = "${mAOut}
  #4 (permalink)  
Old 08-01-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
No sample values

Apologies. The sort off thing suggested by Shell Life is pretty much representative of the sort of thing I am trying to.
Thanks Shell Life - this looks like what I am after. Will give it a whirl.
  #5 (permalink)  
Old 08-01-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
Manipulating variables - part 2!

Looking at this I don't think I have explained myself at all well.

var A contains - essentially - a list of paths to files in a particular dir
var B contains the same but it is a different dir. As the script runs Var A will not be regenerated but with every iteration of a loop var B will.

These two sets of paths *should* be the same. I am looking for matches and if one occurs I want to blank out the var A entry so that it becomes smaller over the course of the script run so as to cut down on the number of entries that have to be considered in subsequent iterations of the loop.

So I want to preserve var A but be able to reduce it in size as the script proceeds.

I hope this is clearer
  #6 (permalink)  
Old 08-01-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Ajcannon,
This is exactly what the shell is doing.

Did you run the script?

I saved the value of 'mA' into 'mAOut' and every iteration of the shell,
the variable 'mAOut' is being reduced.

Place an 'echo ${mAOut}' inside of the loop to watch what is happening.
Closed Thread

Bookmarks

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

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




All times are GMT -4. The time now is 03:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0