Shell script programming (merge and sort)

Source: Internet
Author: User

Shell script programming (merge and sort)
[Cpp] view plaincopy

  1. #! /Bin/bash
  2. # Shell script sorting: merging and sorting
  3. A = (13579)
  4. B = (2468101214)
  5. C =
  6. N = 5
  7. M = 7
  8. I = 0
  9. J = 0
  10. K = 0
  11. While [$ I-lt $ n-a $ j-lt $ m]; do
  12. Iftest $ {a [$ I]}-gt $ {B [$ j]}; then
  13. C [$ k] =$ {B [$ j]}
  14. J = $ ($ j + 1 ))
  15. K = $ ($ k + 1 ))
  16. Else
  17. C [$ k] =$ {a [$ I]}
  18. I = $ ($ I + 1 ))
  19. K = $ ($ k + 1 ))
  20. Fi
  21. Done
  22. # Echo $ I
  23. # Echo $ j
  24. While [$ I-lt $ n]; do
  25. C [$ k] =$ {a [$ I]}
  26. I = $ ($ I + 1 ))
  27. K = $ ($ k + 1 ))
  28. Done
  29. # Echo $ j
  30. # Echo $ m
  31. While [$ j-lt $ m]; do
  32. C [$ k] =$ {B [$ j]}
  33. J = $ ($ j + 1 ))
  34. K = $ ($ k + 1 ))
  35. Done
  36. For (I = 0; I <$ k; I ++ ))
  37. {
  38. Echo-n $ {c [$ I]} ""
  39. }
  40. Echo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.