Unix Script Syntax

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Script Syntax
# 1  
Old 02-28-2008
Unix Script Syntax

Hi Josh

Hope you are doing fine..I have a small requirement but unable to get a syntax for it.

Here is how it is.

There is a Server say ABC.From another Server i need to get records from Server ABC.

Now logic is written as follows.

It creates a file as per sysdate and append the current $$ and then gets the records in the file.
In this process we are getting the two file same of same data.
First file have few records (truncketed file) and the second file have the
full (total file) records including the records in first file

For eg:-

File 2007_12_-16-20764_1.txt for 20071214 20071215 have the 18 Records
File 2007_12_-16-20764_2.txt for 20071214 20071215 have the 186 Records ( included the 18 records)

What we want is only the second file..Now how to check if each of the file is correct is if the file contains a 9 in the end

Here is a Tail of few Lines of a Valid file

1378272549781002 MM 378276160711008 MM 378519137713007 RIVERBED 034213 10003087 0175566881 149035 00004525400+00000000000550100000000000000084020000000000055010000000000000008402000000100000000081CM 154531207313501200711082007110920071122 OI0000000005501HESS 38285 000000000 CAMP HILL PAREF# 000045254 7176129616 11/08/07 23784769232298445230HESS 38285 4175 MARKET STREET CAMP HILL PA 17011 UNITED STATES 840 07005541N 728000002
2378276160711008 378519137713007 +0000000000055010000001+0000000000000000000000 +000000000252178+0000000004521292222DOUGLAS C HAVERSTOCK +00000000012004920000014-00000000032000020000001+0000000003110832+0000000000000002+0000000000000002+0000000000000002A20000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000 0000000000050000000000000000000000000000000020061209000000000000000000000000000000000000000000000000
3378276160711008 +0000000000055010000001+0000000000000000000000 22MM +00000000012004920000014-00000000032000020000001+0000000003110832+0000000000000002+0000000000000002+0000000023062482000010000 000000000000000000000000
4 +0000000024321620000165-000000001186789000001222 20071110 378272549781002 MM +00000001502068720001306-00000002732291120000338+0000000154891072+0000000078292992+0000000032848502+0000000743719192007080000 000000000000000000000000
9 000028389 000221556 KR01025001 20071109 20071110 0000285

An Invalid File could be something like

2378270195921005 379609106972004 +0000000000040200000001+0000000000000000000000 +000000000060857+0000000001529712222MARY CARLEY +00000000004892720000008-00000000014104120000001+0000000000000002+0000000000000002+0000000000000002+0000000000000002A20000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000 0000000000050000000000000000000000000000000020061209000000000000000000000000000000000000000000000000
1378272549781002 JS 378270195921005 AJS2 379610140911008 JS 045371 10001144 0614072677 149035 00000000000+00000000000146400000000000000084020000000000014640000000000000008402000000100000000081CM 110130707313501200711062007110920071128 050000000001464LOUIES OKC OK CITY OKREF# 00000000000 RESTAURANT 11/06/07 1350314530 LOUIE'S ON THE LAKE, L.L. LOUIE'S ON THE LAKE 9401 LAKE HEFNER PKWY OKLAHOMA CITY OK 73120-2075 UNITED STATES 840C07005812N 010000002
2378270195921005 379610140911008 +0000000000014640000001+0000000000000000000000 +000000000034584+0000000000076502222JS +00000000002693420000009+00000000000000020000000+0000000000000002+0000000000000002+0000000000000002+ 0000000000000002A200000000000000000000

So when it gets these records from ABC it should check if last line has a 9 as shown above.If yes then we actually process this file
or else we delete this file becuase we dont want to process this.

Can u help me in this

# 2  
Old 02-28-2008
One way to find the first character of the last line:

First_Char_Last_Line=$(tail -1 file|awk '{print substr($0, 1, 1}')

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Isql and If Exist syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (7 Replies)
Discussion started by: Suresh
7 Replies

2. Shell Programming and Scripting

Isql syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (1 Reply)
Discussion started by: Suresh
1 Replies

3. Shell Programming and Scripting

Help on grep syntax in UNIX

Dear Team /app/Appln/logs/ echo Session used server are 'grep -i pid|grep -i session | cut -d'.' -f1 | awk '{print $9}' | sort | uniq' Output - lxserver01 lxserver02 lxserver03 When I grep session pid in logs server details I can see above distinct server details but I... (6 Replies)
Discussion started by: skp
6 Replies

4. Shell Programming and Scripting

Special IF construct syntax in UNIX

Hi, I don't understand && and || in this context. I thought && is for logical 'AND' and || is for logical 'OR'. && echo "Not empty" || echo "Empty" Please help Thank You (5 Replies)
Discussion started by: TomG
5 Replies

5. Shell Programming and Scripting

Syntax Error in Unix Shell Script

I am trying to run a unix script in my home directory.Snippet below echo "`date '+%Y%m%d_%H%M%S'` Getting ProductList.dat" if ( -f $DIR/ProductList.dat) then cp $DIR/ProductList.dat MigratedProductList.dat else echo "`date '+%Y%m%d_%H%M%S'`ProductList.dat does not exist; Processing... (4 Replies)
Discussion started by: Mary James
4 Replies

6. UNIX for Dummies Questions & Answers

uanble to find while and for loop syntax in unix

Hi friends, I am unable to find for loop or while loop syntax on ksh shell,same syntax is working in other shell ,please suggest a way through. error :syntax error at line 2: `(' unexpected syntax used : for ((i=1;i<=$v1;i++)) thanks, Jcpratap (9 Replies)
Discussion started by: Jcpratap
9 Replies

7. Shell Programming and Scripting

AWK syntax /bailing script error when executing in UNIX

Hi I am trying to execute the following awk script in unix but getting the following error awk: syntax error near line 1 awk: bailing out near line 1 for i in `cat search` do grep -i -l $i *.sas | awk -v token=$i '{print token "\t" $0}' done Please let me know what could be the... (4 Replies)
Discussion started by: nandugo1
4 Replies

8. UNIX for Dummies Questions & Answers

Evaluation syntax in Unix commands

I know this should be simple, but sorry I am fairly new to UNIX and can't find the syntax to make this work. I have the following two commands in a script: x=`expr $(head -1 filename.ext | cut -c16 | grep | wc -l) + 16` del=`head -1 filename.ext | cut -c$x` This works fine as I expect... (2 Replies)
Discussion started by: DJR
2 Replies

9. UNIX for Dummies Questions & Answers

Syntax for own UNIX command

hi All, how can i make my own commamnds for unix shell scripts. lets xmple.. 1-i want to use "down arrow key" for previous runned unix commands. then how to acheive it. 2-Generally TAB --- complete filename or command up to the point of uniqueness ..but here its not working .. I m new to... (1 Reply)
Discussion started by: pradeepcarya
1 Replies

10. HP-UX

Syntax problem with Unix ftp get command

An outside vendor has staged 2 batch files for us and I've tried to retrieve the files using the commands that they've indicated I could use to retrieve one file at a time. I've tried using this command in a shell script after a successful connection to their server: get "$$ ID=IL096869 BID='PGP... (2 Replies)
Discussion started by: mheinen
2 Replies
Login or Register to Ask a Question