Script to output a line missing a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to output a line missing a number
# 1  
Old 07-22-2012
Script to output a line missing a number

Ok, Lets see if I can explain this

We have a script that pulls information from multiple files and outputs it, however I only need 2 Columns (of 11) from it

right now I run the script like this:

tkxtrn | awk '{print $5" "" "$9}'

This gives me column 5 and 9, the only two I care for

What I end up having to do is cat that into a file and pg through 60+ pages or I can pipe a pg to that... to find my (missing) information

the output is similar to this

10-12-5 92
54-23-4
142-1-4 91
1-423-2 35
6-8-454
45-68-4 91
6-99-84 95

only 400+ times.

The issue is, I'm looking for that blank, and there is usually only 1 or 2 missing information in the second(9) column but there are also page breaks of 2-3 blank lines. It always has a 2 digit number, or it is blank.


What I'm wanting is it to say

"searching for missing LD...."
and then output the missing only
54-23-
6-8-454

Hopefully I explained well enough

Last edited by shadowkraze; 07-22-2012 at 10:35 PM..
# 2  
Old 07-22-2012
Does this work for you:

Code:
tkxtrn | awk ' NF > 2 && !$9 { printf( "%s %s\n", $5, $9 ); }'

Should skip blank lines, and print lines only when field 9 (and after for that matter) is missing.
# 3  
Old 07-22-2012
Quote:
Originally Posted by agama
Does this work for you:

Code:
tkxtrn | awk ' NF > 2 && !$9 { printf( "%s %s\n", $5, $9 ); }'

Should skip blank lines, and print lines only when field 9 (and after for that matter) is missing.
-> tkpxtrn | awk ' NF > 2 && !$9 { printf( "%s %s\n", $5, $9 ); }'
Page
File
Page
File
Page
File
Page
File
Page
File
Page
File
Page
File
Page
File

Now if I can only get it to omit Page and file..

Last edited by shadowkraze; 07-22-2012 at 11:37 PM..
# 4  
Old 07-22-2012
In future, having a sample of the input would really help.

This should eliminate file/and page:

Code:
tkxtrn | awk ' !(/File/ || /Page/) && NF > 2 && !$9 { printf( "%s %s\n", $5, $9 ); }'

This User Gave Thanks to agama For This Post:
# 5  
Old 07-23-2012
Quote:
Originally Posted by agama
In future, having a sample of the input would really help.

This should eliminate file/and page:

Code:
tkxtrn | awk ' !(/File/ || /Page/) && NF > 2 && !$9 { printf( "%s %s\n", $5, $9 ); }'

THANK YOU!!! I understand, I put as much in as I could.. alot of the input is information I can't share so I had to simulate the output. Sorry. But that did what I wanted it to for now. Eventually I'm going to try and get it to take that first colomn and pull the employee it refers to. The first column is an emp ID. this file doesn't display the names of the employees, just some useless information to me and those two columns. from that step I have to go though and match it to an emp called by another script and I grep out the ID


for example his will output

6-8-454

I would then take this and do

tkemp | grep -a2 "6-8-454"

Which gives me

Name: YUNAS, XXXXX
ID: 6-8-454

I then know who I need to contact :-D

Hopefully I will get better at this and have this scripted and automated, so it only takes me a few minutes a day instead of an hour.

---------- Post updated 07-23-12 at 07:34 PM ---------- Previous update was 07-22-12 at 10:59 PM ----------

#
echo -e "--- Checking for missing Labor"
sleep 2
#This scans tkxtrn and looks for a missing LD and
#turns it into a variable only works if 1 is missing
LD=`tkxtrn | awk ' !(/File/ || /Page/) && NF > 2 && !$9 { printf( "%s \n", $5 ); }'`
if [ "${LD}" == "" ]; then
echo "No missing LD's found"
else
# This takes the ID of the missing emp and greps it from tkemp
echo "Please correct the missing LD for"
tkemp | grep -ia5 "${LD}"
fi
#------------------------------------------------


It works, and eliminated hours of paging through files!!

Now if I can learn enough to get it to output more than one.. sometimes there are 3 or 4 missing as this only works for one. I have a feeling this is going to be much more involved...

Last edited by shadowkraze; 07-23-2012 at 12:21 AM..
# 6  
Old 07-23-2012
With a small adjustment to your script, it might work for multiple ones. I cannot test it, so I don't know if I've fat-fingered anything, but it's a start:

Code:
#/usr/bin/env bash
echo "checking for missing labour"

#This scans tkxtrn and looks for a missing LD and
#turns it into a variable only works if 1 is missing

nfound=0  # count number found to put out "all ok" message if there were none

# run the pipe and for each LD written, read it into the variable and do the grep on it. 
tkxtrn | awk ' !(/File/ || /Page/) && NF > 2 && !$9 { printf( "%s \n", $5 ); }' | while read LD
do
    (( nfound++ ))
    echo "Please correct the missing LD for: $( tkemp | grep -ia5 "${LD}" )"
done
if (( nfound < 1 ))
then
    echo "No missing LDs found"
fi

There might be a way to do it with just one execution of the 'tkxtrn' command, but without knowing a bit about the output I cannot say. I understand the need to not share sensitive info, so if you're willing to live with a bit of inefficiency, and this works, then go for it.
This User Gave Thanks to agama For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do we display specific row of an output from bottom given line number?

I pass a number to my script. Passing "1" below. ./getfile.sh 1 echo "User entered: $1" ls -ltr *.conf | sed -n '$p' I wish to use ls -ltr i.e list files in ascending order of time the latest showing at the bottom of the output. Number 1 should get me the last row of ls -ltr output i.e... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

Hi everyone :) I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan. Using the code below i am able to generate an image with the slogan text from each line. The image filename is saved matching the last word on each line. Example: Line 1: We do... (2 Replies)
Discussion started by: martinsmith
2 Replies

3. Shell Programming and Scripting

Print line number from piped output

i need to do something like this: script.sh #!/bin/sh echo "hello" echo "My First name is John" echo "My Last name is Smith" echo "I am here to save you a lot of work" sed -n 4,5p $0 i dont want to run the script. i just want to pull out specific line from it. so the logic here... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Incorrect number of command line arguments and missing required files

I am developing a script. This script takes in one parameter which is the name of a file whose content is a list of names of some files. The script can check whether those files exist in current directory. Here is my question: If the number of provided parameters is less than one or one of the... (2 Replies)
Discussion started by: Ray Sun
2 Replies

6. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

7. Shell Programming and Scripting

How do i find the first number in each line and insert dummy string into the missing columns?

Hi, I have one input file with the following content: MY_inpfile.txt Aname1 Cname1 Cname2 1808 5 Aname2 Cname1 1802 47 Bname1 ? 1819 22 Bname2 Cname1 1784 11 Bname3 1817 9 Zname1 Cname1 1805 59 Zname2 Cname1 Cname2 Cname3 1797 27 Every line in my input file have a 4 digit... (5 Replies)
Discussion started by: Szaffy
5 Replies

8. Shell Programming and Scripting

join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like: 1 200.3 -0.3 2 201.7 -0.32 ... 87 200.2 -0.314 I have another file which contains data that was taken at certain of these 87 positions. i.e.: 37 125 42 175 86 142 where the first... (1 Reply)
Discussion started by: jackiev
1 Replies

9. UNIX for Dummies Questions & Answers

how to grep a number from output line

I`m having a output shown below, CFR 235,BBC DM-2 ALL CFR 111,BBC DM-2 ALL CFR 333,BBC DM-2 ALL from the above Output i want to use 235,111,333 as input for other purpose. these no always change every time i run script.so please suggest me the way i could do it with example,i have tried... (5 Replies)
Discussion started by: nitin_aaa27
5 Replies

10. Shell Programming and Scripting

Insert output into file at line number

I need to insert the output of a script into a specific line number of a txt file. I've read the Sed man page and searched the forums and it's not immediately clear how I would go about doing this. (4 Replies)
Discussion started by: pluto7777
4 Replies
Login or Register to Ask a Question