![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
is it homework? if so, have a look at the rules!
|
|
#3
|
|||
|
|||
|
NO!!!! this is not a home work.......
|
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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
|
|
#6
|
|||
|
|||
|
Code:
awk 'NR==1{ if ( $0 ~ /ID/) print }' "file"
|
|
#7
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |