10-05-2006
Finding word in file then print the preceding....
Hi,
I am looking for a way to find a particular word in a file then print a line that precedes this line, as well as this line.
Sometimes in a log file there is only one word per line and I need to print one of the lines leading up to the single worded line.
Example - I can grep for ouch and need line 1 and the ouch line printed as one line for output.
2006-10-04 this is line one
this is line two
this is line three
ouch
this is line four
thx.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
Would like to find a more suitable solution for the following. I have a file eg test.log. In this file, i have to find the line that has "Final rating" which is the starting of the line. I need to print out only 5.75 instead of the whole line using "grep". May I know what suitable command... (8 Replies)
Discussion started by: Kinki
8 Replies
2. Shell Programming and Scripting
Hi frndz,
i have a flat file like,
xxx yyy zzz sss aaa bbb yyy xxx rrr sss ttt yyy ddd zzzz cccc..
look, in this file i want to fetch the substring from one yyy to another one and need to print it then from next values between yyy's..
can you please give me some inputs on this..
... (10 Replies)
Discussion started by: smr_rashmy
10 Replies
3. Shell Programming and Scripting
Hi,
I need to check if a particular name is already in the file or not and i am using following code for this...
match=$(grep -n -e "$output1" outputfiles.txt )
where output1 is the variable name having names in it and outputfiles.txt is the file name ..and i am using ksh
can anybosy... (6 Replies)
Discussion started by: manmeet
6 Replies
4. UNIX for Dummies Questions & Answers
Hi ,
My input file is below like that :-
$cat abc.txt
Service name: test_taf
Service is enabled
Server pool: test_tac
Cardinality: 2
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: true
Failover type: SESSION... (3 Replies)
Discussion started by: sp001
3 Replies
5. Shell Programming and Scripting
Dear All,
assume that we have a text file or a folder of files,
I want to find this pattern followers*.csv in the text file , and get * as the output.
There are different matches and * means every character.
Thank you in advance.
Best,
David (1 Reply)
Discussion started by: davidfreed
1 Replies
6. Shell Programming and Scripting
Hi,
I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file.
Ex:
$ cat "sample.log"
I am searching for a word which is present in this file
We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies
7. Linux
I have a file that looks like this,
P38112 Q12389; Q03532; P43586; Q08208; P37838; P40693; P38805
Q12389 P32892; P36049; Q03532; P43586; Q12176; P38112; P39744; P37838
P11154 P39940
P50094 P50095
P32892 Q12389; Q04660; P43586; P37838; P40693
Q05022 Q08235; Q12176; P39744
P40347 P32333... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies
8. Shell Programming and Scripting
Hi,
I have some data like below:
John 254
Chris 254
Matt 123
Abe 123
Raj 487
Moh 487
How can i print it using awk to have:
254 John,Chris
123 Matt,Abe
487 Raj,Moh
Thanks. (4 Replies)
Discussion started by: james2009
4 Replies
9. UNIX for Beginners Questions & Answers
I have a text file that has some data like:
PADHOGOA1 IOP055_VINREG5_1 ( .IO(VINREG5_1), .MONI(), .MON_D(px_IOP055_VINREG5_1_MON_D), .R0T(px_IOP054_VINREG5_0_R0T), .IO1() );
PADV30MA0 IOP056_VOUT3_IN ( .IO(VOUT3_IN), .V30M(px_IOP056_VOUT3_IN_V30M));
PADV30MA0 IOP057_VOUT3_OUT (... (2 Replies)
Discussion started by: utkarshkhanna44
2 Replies
10. Shell Programming and Scripting
Hello.
Here is a file contents :
declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern
=I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '='
Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies