Problem with outputting multiple lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with outputting multiple lines
# 1  
Old 09-22-2006
Problem with outputting multiple lines

Dear Gurus,

I have this output file:

F1BDEV13 NTIAF101 2006/09/21 14:54:51 14:55:29 1 0560-0570 LAN
F1BDEV14 NTIAF101 2006/09/21 14:55:30 14:55:49 1 0000-0000 LAN
F1FSP001 NTIAF101 2006/09/21 14:55:51 14:55:53 1 0000-0000 LAN
F1NSP001 NTIAF101 2006/09/21 14:55:54 14:56:08 1 0000-0000 LAN

and this is my script:

awk '{if (NR==1) {print $7}}' ${log}/${date}.statuscheck.log
if ("$? != "0000-0000");
then
echo "Transmission Error Check Log File"
endif

i wanted to extract out 0000-0000 (see bold) which indicates the status of my file transmission. i

s there any other ways beside the above script which i have created? Smilie

my current script only check for the 1st line and get the output. what i want is to be able to search all the lines and extract out the result that i want. how do i modify my script? thanks. Smilie

wee
# 2  
Old 09-22-2006
One way :
Code:
while read id1 id2 date hour1 hour2 status filler
do
   if [ "$status" = "0000-0000" ]
   then
      echo "Transmission Error ($id1 $id2)."
   fi
done ${log}/${date}.statuscheck.log

Jean-Pierre.
# 3  
Old 09-22-2006
Code:
awk '$7 != "0000-0000" { print "Transmission Error Check Log File",$7}' filename_uroutputfile

# 4  
Old 09-22-2006
Quote:
Originally Posted by Dhruva
Code:
awk '$7 != "0000-0000" { print "Transmission Error Check Log File",$7}' filename_uroutputfile

it works!! bingo! Smilie thanks!!
# 5  
Old 09-22-2006
Quote:
Originally Posted by lweegp
it works!! bingo! Smilie thanks!!
hi another question...

apparently this is an error, so i would like to return a 1 instead of a 0 how do i go about doing it? thanks again
# 6  
Old 09-22-2006
add
Quote:
exit 1
after print statement in awk
# 7  
Old 09-22-2006
Exit with error status from awk program if transmission error found :
Code:
awk '
   $7 != "0000-0000" { 
      print "Transmission Error Check Log File",$7;
      sts = 1
   }
   END {
      exit sts
   }
' filename_uroutputfile
exit $?

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

4. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

5. Shell Programming and Scripting

Finding several patterns and outputting 4 lines after

I an trying to parse a file looking for pattern1, or pattern2, or pattern3 and when found print that line and the next 4 lines after it. I am using korn shell script on AIX and grep -A isn't available. (1 Reply)
Discussion started by: daveisme
1 Replies

6. Shell Programming and Scripting

Problem outputting increment

With this script the output to the terminal does not increment. Can anyone tell me what I need to do to get this to increment output to the terminal? Here is the output mpath major,minor number ls: /dev/mapper/mpathp1: No such file or directory raw device output 253,44 echo raw device... (5 Replies)
Discussion started by: bash_in_my_head
5 Replies

7. Shell Programming and Scripting

Outputting discarded GREP lines to a file

I had a question about grep. If I grep for something in a file, the output shows me all the lines in which that 'something' is contained in. Is there a way to also output all the lines in which that 'something' wasnt contained in. Say I have a file with a bunch of names and I do: grep scott... (2 Replies)
Discussion started by: ndedhia1
2 Replies

8. Shell Programming and Scripting

Outputting data from multiple lines

Hi guys, looking for a bit of advise, and as I am a complete novice, please excuse the daft questions!! I have a list of events and of which entry looks like this; # # Event 1 # NAME = Event 1 # 12345 : 123 : 1 : 1 : L,1,N : 1,0 : Event # # Event 2 # NAME = Event 2 # 12346... (8 Replies)
Discussion started by: JayC89
8 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

PHP Outputting finite amount of lines from a file

Hi, I have the code below which outputs all the lines of a CSV file but I'd like it to only output 15 lines then save the current line as a variable which could be used (as a link) to display the next 15 lines. I can't get my head around the logic! Please help :D while ($data = fgetcsv($fp,... (1 Reply)
Discussion started by: pondlife
1 Replies
Login or Register to Ask a Question