# Help with shell scripting

**URL:** <https://community.unix.com/t/help-with-shell-scripting/251446>\
**Category:** Shell Programming and Scripting\
**Created:** [October 16, 2009, 3:30am UTC](https://community.unix.com/t/help-with-shell-scripting/251446 "2009-10-16T03:30:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishva79](https://community.unix.com/letter_avatar/vishva79/32/6_449c533f586939b6e5f246632a46421f.png) [@vishva79](https://community.unix.com/u/vishva79)\
**Post date:** [October 16, 2009, 3:30am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/1 "2009-10-16T03:30:03Z")

</div>

HI guys,  
I need to check the base.txt file with the base.lck file and get a resulting base file which checks the last number in the base.lck file and starts with the number after the numbers in the base.lck file.  
Here the base.txt is the list of numbers.  
The base.lck file is something like a buffer which stores the numbers which are used from the base.txt file  
lets name the resulting file as result.txt  
Please try out and help me..  
thanks in advance...

---

<div class="post-metadata">

**Author:** ![zaxxon](https://community.unix.com/user_avatar/community.unix.com/zaxxon/32/660_2.png) [@zaxxon](https://community.unix.com/u/zaxxon)\
**Post date:** [October 16, 2009, 3:33am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/2 "2009-10-16T03:33:19Z")

</div>

What did you try so far? Any particular problem you got stuck with?

---

<div class="post-metadata">

**Author:** ![vishva79](https://community.unix.com/letter_avatar/vishva79/32/6_449c533f586939b6e5f246632a46421f.png) [@vishva79](https://community.unix.com/u/vishva79)\
**Post date:** [October 16, 2009, 5:15am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/3 "2009-10-16T05:15:30Z")

</div>

im relatively new to this shell scripting...  
This is just a part of my task which i am not able to solve  
I solved other tasks and i need this to get solved and move on in this program execution

---------- Post updated at 01:17 PM ---------- Previous update was at 01:14 PM ----------

i donno how to get to the base.txt file which checks the base.lck file

---------- Post updated at 02:33 PM ---------- Previous update was at 01:17 PM ----------

what do i need to code  
??

---------- Post updated at 02:45 PM ---------- Previous update was at 02:33 PM ----------

plz post ur replies...i need answers

---

<div class="post-metadata">

**Author:** ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)\
**Post date:** [October 16, 2009, 5:17am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/4 "2009-10-16T05:17:56Z")

</div>

Bumping up posts or double posting is not permitted in these forums.

Please read the [rules](http://www.unix.com/misc.php?do=cfrules), which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [October 16, 2009, 6:09am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/5 "2009-10-16T06:09:09Z")

</div>

vishva79, I think you will have to provide more detail and a better description of your problem, perhaps an example. I for one do not understand what you mean.

---

<div class="post-metadata">

**Author:** ![vishva79](https://community.unix.com/letter_avatar/vishva79/32/6_449c533f586939b6e5f246632a46421f.png) [@vishva79](https://community.unix.com/u/vishva79)\
**Post date:** [October 16, 2009, 11:44am UTC](https://community.unix.com/t/help-with-shell-scripting/251446/6 "2009-10-16T11:44:28Z")

</div>

E.G:  
vim file1.txt  
98908999897  
76956987698  
76760879878  
21319847985  
12423756867  
23453647876  
23534654567

vim file2.txt  
98908999897  
76956987698  
76760879878

Here file2.txt gets updated frequently.i.e.the last number is not constant.

I want a file3.txt which can check the status of the file2.txt i.e.last number....and can insert next number on wards into a seperate file.

If u can understand my problem,plz respond.Thanks.

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [October 16, 2009, 12:43pm UTC](https://community.unix.com/t/help-with-shell-scripting/251446/7 "2009-10-16T12:43:01Z")

</div>

Perhaps this ?

```nohighlight
awk '/'$(tail -1 file2.txt)'/{pr=1; next} pr == 1 ' file1.txt > file3.txt

```

---

<div class="post-metadata">

**Author:** ![vishva79](https://community.unix.com/letter_avatar/vishva79/32/6_449c533f586939b6e5f246632a46421f.png) [@vishva79](https://community.unix.com/u/vishva79)\
**Post date:** [October 16, 2009, 1:00pm UTC](https://community.unix.com/t/help-with-shell-scripting/251446/8 "2009-10-16T13:00:43Z")

</div>

Dint get the answer..  
anyways thanks a lot for ur help..

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [October 16, 2009, 2:33pm UTC](https://community.unix.com/t/help-with-shell-scripting/251446/9 "2009-10-16T14:33:48Z")

</div>

Perhaps something less cryptic then?

```nohighlight
start=0
prev=$(tail -1 file2.txt) # set prev to the last record in file2.txt
while read rec; do # read every record in file1.txt
  if [$start -eq 1]; then # if it is time to start printing,
    echo $rec # print record to file3.txt
  fi
  if ["$rec" = "$prev"]; then # if record matches prev
    start=1 # start printing the record after this record.
  fi
done < file1.txt > file3.txt

```
