Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, Im begining linux user, i need help in writing a script in K Shell that wil read numbers form file A and match the number to area codes from ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    2

    help

    Hi,
    Im begining linux user, i need help in writing a script in K Shell that wil read numbers form file A and match the number to area codes from File B and then print the number and the matched area code on screen.

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    The question is not very clear... You'd better list small chuncks
    of file A & B e how you want the results displayed.

    In any case you chosed well: bash scripts are very easy and
    you can test immediately each line.
    The small examples I asked you are for identifiying the delimiters
    among number columns. In fact the main system I use is "cut" + field number.

    Go on!... Everyone was a newbie at the beginning! (... and in many fields
    I am still a newbie!)

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    2
    Quote Originally Posted by fiomba View Post
    The question is not very clear... You'd better list small chuncks
    of file A & B e how you want the results displayed.

    In any case you chosed well: bash scripts are very easy and
    you can test immediately each line.
    The small examples I asked you are for identifiying the delimiters
    among number columns. In fact the main system I use is "cut" + field number.

    Go on!... Everyone was a newbie at the beginning! (... and in many fields
    I am still a newbie!)
    Thanks for replying... both are huge files.....
    File A has numbers...
    like
    111111
    22222
    333333
    444444
    and so on


    File B has numbers and city associated with these numbers....

    like 111111---dallas
    222222 ----New York

    and so on....


    i want to write a script that checks the number in file A and then match it with locaitons in File B and then print it on screen..


    like 111111---dallas

  4. #4
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Your problem is to query a fileB on the ground of data in fileA.
    The experts would call it "look-up"
    The solution is:
    Code:
     1 # SimpleQuery.sh
     2
     3 # get the query array from file A
     4 aQuery=`cat fileA`
     5
     6 # verify
     7 for i in $aQuery;do echo $i;done
     8 # output:
     9 # 11111
    10 # 4444
    11 # 45674
    12 # 22222
    13 # 4444
    14 # 33333
    15 # ... ok
    16
    17 # initialize output file to void
    18 # before (ls -l pippo);
    19 # -rw-r--r-- 1 d3 d3 113 2008-12-15 09:35 pippo
    20 > pippo
    21 # after  (ls -l pippo);
    22 # -rw-r--r-- 1 d3 d3 0 2008-12-15 09:35 pippo
    23 # ok 113 --> 0
    24
    25 # applying the query (result in pippo)
    26 for i in $aQuery
    27 do
    28     for j in `cat fileB`
    29     do
    30         echo $j|grep $i >>pippo
    31     done
    32 done
    33
    34 # output:
    35 # cat pippo
    36 # 11111---One
    37 # 4444---Four
    38 # 45674---FFSSF
    39 # 22222---Two
    40 # 4444---Four
    41 # 33333---Three
    42 # ... ok!
    Run by "bash SimpleQuery.sh", after having build the two
    example files (fileA & fileB):
    Code:
    cat fileA   cat fileB
    11111       11111---One
    4444        4444---Four
    45674       45674---FFSSF
    22222       22222---Two
    4444        33333---Three
    33333
    To get the results you must list the output file (line 35)

    Apply then to your actual files... and good luck!

    If you still need help... ask!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...