array + if in linux shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting array + if in linux shell scripting
# 8  
Old 05-20-2011
yes, same directory has all the files.

A files are named as : npkf_123,
qb5f_123
and list1 consists the names of all these files.

whereas, B files are named as : mist_npkf,
mist_qb5f etc
and list2 consists the names of all B files.

I have created the above given shell in the same directory...
# 9  
Old 05-20-2011
list1 and list2?

Post some lines of those files and please use code tags when posting code or data examples.
# 10  
Old 05-20-2011
PHP Code:
List 1
npkf_123
qb5f_123
 
list2 

mist_npkf
mist_qb5f 
# 11  
Old 05-20-2011
Assuming the name of a Bfile is "mist_" and the part before the "_" of the Afile:
Code:
while read Afile
do
  file=${Afile%_*}
  Bfile="mist_"$file
  awk 'NR==1{s=$1; next}
  $2=="BBM" && $5==s {print $4}' $Afile $Bfile > $file"456"
done < List1


Last edited by Franklin52; 05-23-2011 at 10:44 AM.. Reason: replaced "mist_" file with "mist_"$file
# 12  
Old 05-21-2011
Hi franklin,

The above code gives the error :
Quote:
Usage: file [-bcikLhnNsvz] [-f namefile] [-F separator] [-m magicfiles] file...
file -C -m magicfiles
Try `file --help' for more information.
# 13  
Old 05-21-2011
Hi.

I imagine this line:
Code:
Bfile="mist_" file

should be:
Code:
Bfile="mist_"$file

This User Gave Thanks to Scott For This Post:
# 14  
Old 05-21-2011
hi,
the above code is also giving the error
Quote:
fatal: cannot open file `mist_' for reading (No such file or directory)
Whereas, B files are starting with "dist_", i cant understand, wotz the problem....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array size in C shell scripting

Hi, I would like to know how to define the size of the array in c shell scripting. (15 Replies)
Discussion started by: gopishrine
15 Replies

2. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

3. Homework & Coursework Questions

Linux Shell Scripting If-else and Case

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is what is asked: If the user enters ‘3’, prompt the user for two file names. Verify that the file names... (2 Replies)
Discussion started by: cindy01
2 Replies

4. Shell Programming and Scripting

Assigning array values using awk in shell scripting

hi My script as below #!/bin/ksh for i in `seq 1 7` do a=$(awk '{print $i}' /home/rama/expenese.txt) done for i in `seq 1 7` do echo "${a}" done content of expense.txt is as below 5032 210179 3110 132813874 53488966 11459221 5300794 I want output as... (6 Replies)
Discussion started by: Ramakrishna V
6 Replies

5. Shell Programming and Scripting

Linux/Unix shell scripting vs Perl

Hi, I have general question: i have good working Perl script with .pl extension, and now I have to migrate all to another Linux box, and I was told that I can use only shell scripting, so I'm not sure how different those two things are, will it work without any changes . Is there anything smart I... (6 Replies)
Discussion started by: trento17
6 Replies

6. Shell Programming and Scripting

Shell Scripting Linux

In shell Can I pass " to a program ? If not what is the work around ..? Can I define * as a wild card charecter that will return all the values from the files ..? I am trying to create a tool that will return the values from a property file . This tool has to support all the wild card... (1 Reply)
Discussion started by: app1sxv
1 Replies

7. Linux

Linux/Unix Shell Scripting Book

I want to learn Linux/Unix shell scripting, I searched this forum but got some results for Unix Admin books and general Linux books. Would someone recommend a good Linux Shell Scripting book? I did order one book A Practical Guide to Linux(R) Commands, Editors, and Shell Programming ... (4 Replies)
Discussion started by: thoughts
4 Replies

8. Linux

Linux game programing or just shell scripting

Well Acording to my job... Anyhelp plz. I need some basic scripting stuff. (3 Replies)
Discussion started by: Irish Jimmy
3 Replies

9. Linux

Difference between Linux and Unix and also C and C++ and also about Shell Scripting

Please Let me know this Que and Ans please Because i applied for a H1B VISA nad i have a INTERVIEW as soon so please "Difference between Linux and Unix and also C and C++ and also about Shell Scripting about all Questions and Answers ." (3 Replies)
Discussion started by: madhav
3 Replies

10. Shell Programming and Scripting

Shell scripting for Unix and/or Linux

Anyone here knows any reasonably priced courses for independent (not corporate) users that can point me to. Already know Unix commands/vi/etc but now need scripting too. Any replies will be appreciated. (2 Replies)
Discussion started by: FastFood
2 Replies
Login or Register to Ask a Question