tags:

views:

53

answers:

3

Hiall,I need to deal with a file which seems as follows:

1234
4343
5345345
53453
4343

And what I want to do is to execute follow command to the number of each line:

grep $num1 ./somepath  #get num1_res

Then write $num1 and $num1_res to another file which will be:

1234 32
4343 234
5345345 349
53453 78
#...etc

Any good solution by sed?Or some other simple way?

Thanks.

+4  A: 

Your requirements are a bit murky, but this should get you most of the way:

while read value
do
  echo "$value $(grep "$value" somepath)"
done < somefile
Ignacio Vazquez-Abrams
+1  A: 

you can use awk. (Please try to describe your question more clearly next time). Based upon guesswork of what you want.

awk 'FNR==NR{
  list[$0]
  next
}
{
  for(i in list){
    if ( $0~i){
      print i,$0
    }
  }
}
' thelist ./somepath/myfile
ghostdog74
A: 
grep -f file_with_num1_vals file_with_num1_res_vals
Dennis Williamson