Manipulating data in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulating data in variable
# 1  
Old 08-01-2007
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  
Old 08-01-2007
A sample value of A (or B for that matter) would help....
# 3  
Old 08-01-2007
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  
Old 08-01-2007
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  
Old 08-01-2007
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  
Old 08-01-2007
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.
# 7  
Old 08-01-2007
Variable Manipulation

Shell Life

my mistake - I did not run it - I looked at it and did not appreciate it *did* do what I wanted.

All is now well - thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Manipulating Data Records for reporting

Hello All, I have Data Records (DRs) with the following format: ... (2 Replies)
Discussion started by: EAGL€
2 Replies

2. Shell Programming and Scripting

Data manipulating script. Please HELP!

Dear friends, I'm struggling to preparing a bunch of gromacs input files, say manually. It's really a time-consuming work without any techniques. I suppose that it could be done by a smart script automatically. But I lack some basic knowledge on scripting. Please help! My original input looks... (3 Replies)
Discussion started by: liuzhencc
3 Replies

3. Shell Programming and Scripting

Manipulating xml data with awk

Hi everyone, I have a little bit of complicated task to finish with AWK. Here it is; I have a data file in xml format which looks like this <data> a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5 d1 d2 d3 d4 d5 e1 e2 e3 e4 e5 </data> lets say each data block contains 5 rows and 5 columns,... (13 Replies)
Discussion started by: hayreter
13 Replies

4. Shell Programming and Scripting

Manipulating a variable using sed (solved)

Hi, My variable has value as this: tvar1="bool_risk_enabled" Boolean "true" Now I need to replace this true with false. Which is the best way to do this? Can we do this with sed command? Please help me. ---------- Post updated at 05:23 PM ---------- Previous update was at 05:00 PM... (2 Replies)
Discussion started by: pravintse
2 Replies

5. Shell Programming and Scripting

Need help in manipulating string variable

I have written a shell script to do some processing and have to manipulate a variable. Basically, the variable is like this -- var=set policy:set cli My purpose is to split it into two variables based on the position of ":". To get the right end, I am doing this -- vaa1=${vaa#*:} ... (1 Reply)
Discussion started by: Dev_Sharma987
1 Replies

6. Shell Programming and Scripting

reading from two files and manipulating the data

hi i have a file of the following format FILE1 5 937 8 1860 1850 1 683 2 1 129 2 2 5 938 8 1122 1123 1 20 520 4 1860 1851 1 5 939 8 1122 1124 1 20 521 4i have another file which... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

7. Shell Programming and Scripting

manipulating data

Hi guys Firstly, I'd like to say hi and how great this forum is. I'm not new to UNIX but am relatively new to scripting. I have a personal project that I'm working on just to try and speed up my learning. I working with a text file, well more of a logfile really. It has several columns of... (6 Replies)
Discussion started by: abcd69
6 Replies

8. Emergency UNIX and Linux Support

Manipulating Data

Hi. I haven't had to write bash scripts in a long time and have a simple task to do, but need some help: Input: chrY:22627291-22651542 chrY:23045932-23070172 chrY:23684890-23696359 chrY:25318610-25330083 chrY:25451096-25462570 chr10:1054847-1061799 chr10:1058606-1080131... (7 Replies)
Discussion started by: awknerd
7 Replies

9. Shell Programming and Scripting

Manipulating Pick multi dimensional data with awk.

Hi. I am reasonably new to awk, but have done quite a lot of unix scripting in the past. I have resolved the issues below with unix scripting but it runs like a dog. Moved to awk for speed and functionality but running up a big learning curve in a hurry, so hope there is some help here. I... (6 Replies)
Discussion started by: mike.strategis
6 Replies

10. Shell Programming and Scripting

Manipulating a variable across multiple shell scripts

I have a shell script similar to: #!/bin/sh a=1 source a1.sh -- Modifies a source a2.sh -- Modifies a echo "After execution, value of a is $a" What i need is a1.sh script modify the same variable a and same with a2.sh. Now the echo "After execution, value of a is $a" should print the... (1 Reply)
Discussion started by: indianjassi
1 Replies
Login or Register to Ask a Question