Finding a character in first line of a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a character in first line of a record
# 8  
Old 07-19-2007
Just one more .........what if i need to to move a file which does not have ID .....to afolder ? for the below code, what changes do i need to make:


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

do we




Thanks again for ur help
# 9  
Old 07-19-2007
Quote:
Originally Posted by bsandeep_80
Just one more .........what if i need to to move a file which does not have ID .....to afolder ? for the below code, what changes do i need to make:


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

do we

Thanks again for ur help
Code:
while read filename
do
  line=$(head -1 $filename)
  if [[ $line = *ID* ]] ; then
    echo "Found ID in $filename"
  else
    # move the file to some folder
    mv $filename /some/folder
  fi;
done < list_of_filenames.txt

# 10  
Old 07-19-2007
thanks....Smilie
# 11  
Old 07-19-2007
Or:

Code:
IFS= ;mv $(for f in *;do read<"$f";case $REPLY in (*id*)echo "$f";;esac;done) afolder

# 12  
Old 07-26-2007
Hi All,

I have taken this script to get the required results , but when i run this manually it works fine but when i run this as a cronjob this fails:
while read filename
do
line=$(head -1 $filename)
if [[ $line = *ID* ]] ; then
echo "Found ID in $filename"
else
# move the file to some folder
mv $filename /some/folder
fi;
done < list_of_filenames.txt

The error that i get is ": syntax error at line 25: `line=$' unexpected"

this works fine if i run this manually.


Can anyone help me please
# 13  
Old 07-26-2007
When you run a job in a cron, it runs on your home directory and it does not
execute your '.profile', thus, it does not know about your PATH nor any other
environment variable.

Either place the input file in your home directory or assign a specific path
to it.

Also make sure you are running ksh by placing the following as the first line of
your shell script:
Code:
#!/bin/ksh


Last edited by Shell_Life; 07-26-2007 at 11:30 AM..
# 14  
Old 07-26-2007
THis is the script that i am using:

FROM_DIR=/home/sandy_home/cc3; export FROM_DIR
LOG_DIR=/home/sandy_home/log_dir; export LOG_DIR

echo "NUMBER OF cc3 files BEFORE process STARTS-IF A FILE IS MISSING/NOT TRANSFERRED CONTACT Sandeep" > $LOG_DIR/che
ckfile.log

cd $FROM_DIR


ls -l *.cc3 >> $LOG_DIR/checkfile.log
for ccfile in $FROM_DIR/*.cc3

do
line=$(head -1 $ccfile)
if [[ $line = *ID]];
then
echo "----------------------------FOUND ID in $ccfile------------------------------" >> $LOG_DIR/checkfile.log
else
echo "---------------------------- ID NOT FOUND in $ccfile--------------------------" >> $LOG_DIR/checkfile.log

mv $ccfile /home/sandy_home/failed

echo "-----------The file that had no ID has been moved to failed directory---" >> $LOG_DIR/checkfile.log
fi;
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding the Latest record

Dear All, I have getting data as follows, the second field signifies table name and last one is time stamp. I have return always latest record based on time stamp. Could you please help me ? I/P ==== ... (1 Reply)
Discussion started by: srikanth38
1 Replies

2. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

3. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

4. Shell Programming and Scripting

How to Remove the new line character inbetween a record

I have a file, in which a single record spans across multiple lines, File 1 ==== 14|\n leave request \n accepted|Yes| 15|\n leave request not \n acccepted|No| I wanted to remove the '\n charecters. I used the below code (foudn somewhere in this forum) perl -e 'while (<>) { if... (1 Reply)
Discussion started by: machomaddy
1 Replies

5. Shell Programming and Scripting

finding the incorrect record

Hi , I have a scenario where i have to find the incorrect records in the file. In our comma delimited file , we have the following to be taken care : 1) if there is new line character then we have to capture the current line and the next line as error record Ex : In a comma... (8 Replies)
Discussion started by: ashwin3086
8 Replies

6. Shell Programming and Scripting

Reject the record if the record in the next line does not begin with 2.

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten 2eleven 2twelve 1thirteen 2fourteen The output should be: (5 Replies)
Discussion started by: supchand
5 Replies

7. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

8. Shell Programming and Scripting

Finding longest line in a Record

Good Morning/Afternoon All, I am using the nawk utility in korn shell to find the longest field and display that result. My Data is as follows: The cat ran The elephant ran Milly ran too We all ran I have tried nawk '{ if (length($1) > len) len=length($1); print $1}' filename The... (5 Replies)
Discussion started by: SEinT
5 Replies

9. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

10. Shell Programming and Scripting

Character count per record

I have a flat file. How can i retrive the character count per record in whole file. Can anybody assist me on this Cheers (9 Replies)
Discussion started by: subrat
9 Replies
Login or Register to Ask a Question