0

I have 2 files with multiple fields. File A is dynamic which has users logged in everyday and their login times and date. File B has the total number of users and their airport codes. File B is a static file. I need to print the File A data along with the airportcodes of the users. I used the below script..

A=`cut -d " " -f1 /data/sampleupdatedreport.csv`
for A
do
grep $A /home/s399682/StarUsers.txt >tmp_today.csv
done

It is not working. Please help me to find a solution for this. Thanks very much in advance!!!

1
  • It would be helpful to show some sample data from the 2 files. Commented Nov 27, 2013 at 15:36

2 Answers 2

1

Your script can be written as:

grep -f <(cut -d " " -f1 /data/sampleupdatedreport.csv) /home/s399682/StarUsers.txt >tmp_today.csv

This would match all lines in /home/s399682/StarUsers.txt that match the output produced by the cut command.


If you really wanted to write a script, you could say:

while read -r line; do
  grep "$line" /home/s399682/StarUsers.txt
done < <(cut -d " " -f1 /data/sampleupdatedreport.csv) > tmp_today.csv
Sign up to request clarification or add additional context in comments.

Comments

1

You might be looking for join...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.