Sponsored Content
Top Forums Shell Programming and Scripting Help awking a 'head -1 file.txt' input Post 302401310 by tmf33uk on Friday 5th of March 2010 01:14:50 PM
Old 03-05-2010
Help awking a 'head -1 file.txt' input

Hi there,

my ksh script collects a procstack trace for a particular pid and then greps it by a transaction id to find out the pthread ID:
---------- tid# 1876087 (pthread ID: 4466) ----------

So the pthread ID I want is 4466 in this case, and it is assighed to the variable $pthread. This works fine so far.

After this point, I need to read the first line of a few files whose names are composed by several variables in $HEAD_FILE and a number that it reads from file task2. This currently contains:
32888
So HEAD_FILE will be /logs/eComm_esn_32888.log and the loop will only run once. The first line of this file contains:
1021 2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN

I want to set a condition that if field number 15 is equal to the pthread ID (4466) it should print the whole line. Otherwise not. AWK has difficulty in reading the first few characters, so I have used sed to replace them with "nothing" (8 dots).
This makes 4466 be in the $14th position now so I can change the condition.

Here´s the relevant part of the script:
========
Code:
## Take a procstack trace of the pid to find the pthread_id
                        procstack $PID > "${OM}_procstack_${PID}.txt"
                        pthread=`cat $OM_procstack_$PID.txt |grep $TID | sed -e 's/^.*ID: //' -e 's/).*//g'`
                        echo "   "
                        echo "------pthread ID corresponding to transaction $TID is $pthread ------" >> $LOG
                        while read line
                           do
                                HEAD_FILE=`head -1 /logs/eComm_${line}.log | sed -e 's/^........//g'`
                                echo $HEAD_FILE
                                awk '$14 == 4466 {print $14, $15, $16}' < $HEAD_FILE
                           done < task2
                fi
        done < tasks

=======

Running this as it is gives me the following:

Code:
2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN
No such file or directory
./orange.sh[83]: 2010-03-02 17:06:17 0000-00-00 00:00:00 +0100 00000000 001 003f 0001 09 eComm 32888 893162 4466 /logs/eComm_32888.log 7.8.2.8 [19237] ESN: cannot open

=======


So it echoes the value of HEAD_FILE as it understands it now, and the number I am interested in is in 14th position, but I don´t know how to get around the 'cannot open' error to make my condition work.

I only want the 1st line of the file read in the loop which contains the number matching the value of $pthread, obtained a little earlier (4466). Does anyone have any ideas of what I am doing wrong? I think I´ve been staring at this too long..

Thanks in advance!
T.

Last edited by radoulov; 03-05-2010 at 03:03 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to input .txt file into .xls spreadsheet

I need to take the totals from my script and input them into a excel spreadsheet. Right now, I just copy and paste. Is there an easier way? 3906 is the total jobs in ABEND state 4005 is the total jobs in SUCC state 1050 is the total jobs in HOLD state (1 Reply)
Discussion started by: wereyou
1 Replies

2. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

3. Shell Programming and Scripting

Input file redirect in output path and want name as inputfilename_new.txt

not required this time (6 Replies)
Discussion started by: Sandeep_Malik
6 Replies

4. Shell Programming and Scripting

cat vs head vs readline get variable from txt file

I have a file with a single filename in it, which I want to assign to a BASH variable, so I've been trying: c=$(head -1 somefile) echo $c which outputs correctly, but them when I do ... somecommand $c it says it can't find the file, is that because it's grabbing the whole line, and... (5 Replies)
Discussion started by: unclecameron
5 Replies

5. Shell Programming and Scripting

Get the input from user and save it as .txt file

Hi friends, I am pretty new to shell scripting, please help me in this Scenario. for example, If I have one file called input.txt once I run the script, 1.It has to delete the old input.txt and create the new input.txt (if old input.txt is not there, no offence, just it has to create a... (2 Replies)
Discussion started by: Padmanabhan
2 Replies

6. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

7. Shell Programming and Scripting

Grepping or awking multiple lines in a file - regex

data.txt: hellohellohello mellomello1mello tellotellotellotello bellobellowbellow vellow My attempts: egrep ".*mello1\n.*bellow" data.txt awk '/.*mello1.*\nbellow/' data.txt how can i search for patterns that are on different lines using simple egrep or awk? i only want the... (7 Replies)
Discussion started by: SkySmart
7 Replies

8. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

9. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

10. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies
pthread.h(3HEAD)						      Headers							  pthread.h(3HEAD)

NAME
pthread.h, pthread - threads SYNOPSIS
#include <pthread.h> DESCRIPTION
The <pthread.h> header defines the following symbols: PTHREAD_BARRIER_SERIAL_THREAD PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DISABLE PTHREAD_CANCELED PTHREAD_COND_INITIALIZER PTHREAD_CREATE_DETACHED PTHREAD_CREATE_JOINABLE PTHREAD_EXPLICIT_SCHED PTHREAD_INHERIT_SCHED PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_RECURSIVE PTHREAD_ONCE_INIT PTHREAD_PRIO_INHERIT PTHREAD_PRIO_NONE PTHREAD_PRIO_PROTECT PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_PRIVATE PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_SYSTEM The types listed below are defined as described in <sys/types.h>. See types.h(3HEAD). pthread_attr_t pthread_barrier_t pthread_barrierattr_t pthread_cond_t pthread_condattr_t pthread_key_t pthread_mutex_t pthread_mutexattr_t pthread_once_t pthread_rwlock_t pthread_rwlockattr_t pthread_spinlock_t pthread_t ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
sched.h(3HEAD), time.h(3HEAD), types.h(3HEAD), pthread_attr_getguardsize(3C), pthread_attr_init(3C), pthread_attr_setscope(3C), pthread_cancel(3C), pthread_cleanup_pop(3C), pthread_cond_init(3C), pthread_cond_signal(3C), pthread_cond_wait(3C), pthread_con- dattr_init(3C), pthread_create(3C), pthread_detach(3C), pthread_equal(3C), pthread_exit(3C), pthread_getconcurrency(3C), pthread_getsched- param(3C), pthread_join(3C), pthread_key_create(3C), pthread_key_delete(3C), pthread_mutex_init(3C), pthread_mutex_lock(3C), pthread_mutex_setprioceiling(3C), pthread_mutexattr_init(3C), pthread_mutexattr_init(3C), pthread_mutexattr_init(3C), pthread_mutex- attr_gettype(3C), pthread_mutexattr_getprotocol(3C), pthread_once(3C), pthread_rwlock_init(3C), pthread_rwlock_rdlock(3C), pthread_rwlock_unlock(3C), pthread_rwlock_wrlock(3C), pthread_rwlockattr_getpshared(3C), pthread_rwlockattr_init(3C), pthread_self(3C), pthread_setcancelstate(3C), pthread_setspecific(3C), attributes(5), standards(5) SunOS 5.10 9 Sep 2004 pthread.h(3HEAD)
All times are GMT -4. The time now is 06:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy