The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK - if last line/record do something PacificWonder Shell Programming and Scripting 3 06-05-2008 08:13 PM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 11:15 AM
Showing an extra record/line srivsn Filesystems, Disks and Memory 1 05-06-2006 06:35 AM
Finding character position in file dhananjaysk Shell Programming and Scripting 5 03-23-2006 08:49 AM
how to extract last line in record bjorb Shell Programming and Scripting 7 10-17-2005 11:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-17-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
Finding a character in first line of a record

HI,

I am pretty new to Unix scripting. I will need help in Finding a character in first line of a file or a set of files.

The scenario is as follows:

Lets consider a set of files which is having a character "ID"(without quotes) in the first line of each file.I need to find this character in the first line of each file and if the result of this is positive then i have to say echo"ID found in file" otherwise echo "ID not found in the file"

Can anyone help me with this. I will be very Gratefull

Thanks,
Sandy
Reply With Quote
Forum Sponsor
  #2  
Old 07-17-2007
DukeNuke2's Avatar
Soulman
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 1,466
is it homework? if so, have a look at the rules!
Reply With Quote
  #3  
Old 07-17-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
NO!!!! this is not a home work.......
Reply With Quote
  #4  
Old 07-17-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
I have tried searching this through google from past three days.....but i am not able to find any answers on this.......can anyone help me out ...

Thanks,
Sandy
Reply With Quote
  #5  
Old 07-17-2007
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Perhaps this.

Code:
while read filename
do
  line=$(head -1 $filename)
  if [[ $line = *ID* ]] ; then
    echo "Found ID in $filename"
  else
    echo "No ID in $filename"
  fi;
done < list_of_filenames.txt
Reply With Quote
  #6  
Old 07-17-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
awk 'NR==1{ if ( $0 ~ /ID/) print }' "file"
Reply With Quote
  #7  
Old 07-18-2007
Registered User
 

Join Date: Jul 2007
Posts: 99
Thanks so much.....u guys are awesome.......i hope that i am also as good as u guys and help someone in this forum in the comming months.

Thanks and regards,
Sandy
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0