![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Append Header and Trailer | balzzz | UNIX for Dummies Questions & Answers | 2 | 01-06-2008 08:19 AM |
| Copy all the files with time stamp and remove header,trailer from file | ksrams | UNIX for Dummies Questions & Answers | 35 | 07-30-2007 03:15 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 01:15 PM |
| Strip 3 header lines and 4 trailer lines | ganesh123 | Shell Programming and Scripting | 9 | 03-10-2007 05:15 PM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 03:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Checking the header and trailer for a given string and if not found, exit out of the
hi,
How to check a given file for a string and if it's not found, exit out ofthe script? e.g. a file Test123 is there whose header begins with #bt and trailer begins with #ed. I have to check if the header and trailer matches as above and if not, exit out of the script. How can we do it in Unix and perl. Thanks in advance. |
|
||||
|
Code:
#!/bin/ksh # $1 = input file found=0 head -n 1 $1 | grep -q '^#bt' && tail -n 1 $1 | grep -q '^#ed' && found=1 if [[ found -eq 0 ]] ; then exit 1 fi echo "okay" tested with this file: Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|