![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a file line by line | VENC22 | UNIX for Dummies Questions & Answers | 4 | 10-30-2008 11:09 AM |
| read a file line by line in ksh | chella | Shell Programming and Scripting | 3 | 08-29-2008 02:57 AM |
| read the file line by line | kittusri9 | Shell Programming and Scripting | 3 | 04-24-2008 09:26 AM |
| Read string from a file,plz help me to check | joshuaduan | Shell Programming and Scripting | 1 | 05-11-2007 04:12 AM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 09:47 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Read last line of file to check for value
Folks
How best to read the last line of a file, to check for a particular value? This is the last line of my file...... 00000870000002000008 0000000020000 ......I need to check that this line contains '70' in positions 7 and 8, before I continue processing. Regards ... Dave |
|
||||
|
Quote:
You can try the below and apply the condition according to the logic of your code : Code:
x='00000870000002000008 0000000020000'
/home/ans >echo $x | awk '{ print substr($0,7,2); }'
70
/home/ans >echo ${x:6:2}
70
|
|
||||
|
I've coded as follows, as I don't know the name of my file (only the prefix), and also there may be mulitple files. I need to check all the files for '70' before I continue processing. I get the error at the bottom:
Code ===== icofile=`ls -l /Invoices |grep DAAS | awk '{print $9}'` if [[ $icofile != "" ]] then for files in $icofile do if [ `tail -1 $files | cut -c7-8` -eq "70" ] then echo "File correct format, has record 70..." >>$logfile else echo "File incorrect format, missing record 70..." >>$logfile exit 2 fi done echo "Sending $icofile to Server" >>$logfile else echo "No files to send across..." >> $logfile exit 3 fi Error ===== "./Transfer.DAAS[25]: test: 0403-004 Specify a parameter with this command." (where line 25 is my check for '70') |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|