The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-07-2007
er_ashu er_ashu is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 50
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.
  #2 (permalink)  
Old 11-07-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,811

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:
#bt header
data
data
data
#ed trailer
  #3 (permalink)  
Old 11-08-2007
er_ashu er_ashu is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 50
Thanks a lot....
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0