Can someone please help me to learn how to deal with loops, arrays and grep?
I have two arrays (lets say I and j) each in a separate file
Quote:
Ruby, Kate, Askley, John ....
Smith, Brown, Green, Casey, ...
And have file with lines of data I need to extract, such as
Ruby Smith: some text here
Ruby Smith: some other text here
Ruby Brown: some text here
Ruby Green: some text here
And I need each of these names into one new file; so each name category will have its own file
Now sure what I think is the right thing and I don't know the syntax... so would appreciate your help
Would something like this even work? How is it going to know what is my “I” and “J” when they are in my files? Should I give a file name?
and I wonder whether the $1file will increase as well? or shall I write something to add that as well?
I want to match one name from names list with a family name on the family name list
but some of the lines on my maindatafile have a middle name; like Ruby Anne Smith
I want anything starting with Ruby and ending in Smith in one file.
is grep what I need to use for that?
---------- Post updated at 12:01 PM ---------- Previous update was at 11:54 AM ----------
Thank you very much for sending me the right syntax of the code
I have some question
Do I have to define I and J before that code?
or is there a way I can tell it to read from two files?
---------- Post updated 05-29-12 at 08:58 AM ---------- Previous update was 05-28-12 at 12:01 PM ----------
i have tested the code with my data and there seems to be a problem
my code now looks like this
i dont know y i only get one output and that is for the last element in ARRAY and i get it combined, so I get an output of all in one file
john smith ....
john brown ...
john green ...
so it seems to be over written but then again each should be in a separate file
Quote:
output x = john smith
output y = john brown
output z = john green
Hey ,
i have this script and i have these loops so it can find a match between 2 arrays :
ARRAY_1=(one two three)
ARRAY_2=(A B C)
VAR='B'
for NUMBERS in "${ARRAY_1}"
do
for LETTERS in "${ARRAY_2}"
do
if ];then
VAR='LETTERS'
... (2 Replies)
I am trying to read a file line by line and then search that line in another file and get a particular column from the second file.
I have written this code.but its not working properly
#!/bin/sh
while read keyword in duplicate.txt
do
echo $keyword
while read line
do
... (7 Replies)
I write this bit of code to calculate the mean and variance for all the files in one directory and print the mean and variance in a separate folder but with the same file name.
FILES="data/*"
for X in $FILES
do
name=$(basename $X)
awk '{x=$0; s+=$0; n++}
END{mean=s/n; for (i in x){ss... (20 Replies)
hi people,
I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this?
Ex:
Code:
11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa
21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa
31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa... (1 Reply)
Hello All,
I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database.
To this, I have to construct a loop that checks a specified folder for a file.
If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Hi folk,
Hope you enjoy the summer.
I am stock after one day working, the problems are the following:
1) I want to write a for loop in a shell script code that has a double precision step as:
#!/bin/bash
START=0.00001
STOP=0.001
for((i = START ; i< STOP ; i=2*i)) do
echo "$i"... (1 Reply)
hi guys,
i have an array called ARRAY which has elements in it... i am trying to assign elements of ARRAY to master_array..
i get a =: command not found error..
i=0
while
do
${master_array}=${ARRAY}
((i++))
done
is there something i am missing? (4 Replies)
Ok, I've already completed the task this is for, but now I'm trying to go back and find more eloquent solutions for future reference. I have a report I've generated that is formatted like this:
1033 1
1079 4
1453 5
2205 6
1933 7
461 8
646 9
1655 12
975 13
1289 14
The first number is... (3 Replies)
Hi,
I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares.
For example:
file1 has a list of user ids (about 900) from the company's e-mail server.
file2 has a list of user ids (about 50 or so) from... (7 Replies)