Help with shell script - Unix Gurus calling


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with shell script - Unix Gurus calling
# 1  
Old 01-24-2006
Help with shell script - Unix Gurus calling

Unix Gurus,

I have been breaking my head to get this done..seems simple..

I need to read a flat file and based on a key word in a line, i need to skip the previous 3 lines.

eg :

Line1
Line2
Line3
Line4
Line5
Line6
Error
Line7
Line8
Line9
Error
Line10
Line11
Line12

I will read this file, and awk for the first word. If the first word is 'Error', then i need to skip the previous 3 lines.
At the end collect the o/p into another file or display.

The above example at the end should look like :

Line1
Line2
Line3
Line10
Line11
Line12

I tried going the sed way,
sed -n '/Error/{N;N;N;p;}' will give me the nexe 3 lines,
but my requirement is to skip the previous 3 lines.
I tried by reading the file in reverse ( tail -r file ) and then using sed.
With this i can get the 3 lines that i want, but how to skip these lines...i need to get everything in the file except these 3 lines !

Any help is appreciated.

Thanks,
R.

Last edited by ravred; 01-24-2006 at 09:01 PM..
# 2  
Old 01-24-2006
Got perl? Try...
Code:
perl -00pe 's/(.*\n){3}Error.*\n//g' file1

# 3  
Old 01-25-2006
Hi Ygor,

Thanks for the reply.
That works pefect.

Apprciate the quick response.

Regards,
R
# 4  
Old 01-25-2006
How about a non-perl solution, anyone ?
# 5  
Old 01-26-2006
here's a non-perl solution,

Code:
# !/usr/bin/ksh

print=""
count=0

cnt=`cat filename | wc -l`
while [ $cnt -ge 1 ]
do
sed "$cnt"q filename | tail -1
cnt=$(($cnt - 1))
done | while read line
do
if [ $count -ne 0 ]
then
count=$(($count - 1))
continue
fi
if [ $line = "Error" ]
then
count=3
continue
fi
print=$line" "$print
done

echo $print | tr ' ' '\n'

exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have exactly same issue @vikas_trl had in following link: https://www.unix.com/shell-programming-and-scripting/259854-control-not-returning-sqlplus-calling-unix-shell-script.html I wonder if he or somebody else could find the issue's cause or the solution. Any help would... (4 Replies)
Discussion started by: RicardoQ
4 Replies

2. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have a UNIX script which will prepare anonymous oracle pl/sql block in a temporary file in run time and passes this file to sqlplus as given below. cat > $v_Input_File 2>>$v_Log << EOF BEGIN EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16'; EXECUTE... (1 Reply)
Discussion started by: vikas_trl
1 Replies

3. UNIX for Dummies Questions & Answers

Calling all the awk gurus out there.

Hi all, I just signed up to the forums, although, I have lurked on here for awhile. Anyways, my issue is I am trying to get awk to spit out something I can use without having to spend hours in excel hell haha. So, I used sed to replace the spaces with semicolons and redirected that to a file. ... (6 Replies)
Discussion started by: savigabi
6 Replies

4. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

5. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

7. Shell Programming and Scripting

calling mysql gurus : need help with my view

hi there I have a view which is working fine, but i have been told that i need to make sure the resulting output excludes all rows with nic_status equal to the string "removed". Does anybody know in which part of the code below i would place the conditional ... WHERE nic_status !=... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

8. Shell Programming and Scripting

Calling a request set from Unix shell Script

Hi All, I want to call a concurrent request set from a shell script. I am getting the syntax error "syntax error at line 417 : `(' unexpected" in the below script. v_request_id=fnd_request.submit_request(application => 'APPL_SHORT_NAME' ,program => 'PROGRAM_SHORT_NAME' ... (4 Replies)
Discussion started by: swatipevekar
4 Replies

9. Shell Programming and Scripting

Calling procedure through Unix Shell

how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

10. Shell Programming and Scripting

Calling an Oracle Stored Procedure from Unix shell script

hai, can anybody say how to call or to execute an oracle stored procedure in oracle from unix... thanks in advance.... for ur reply.... by, leo (2 Replies)
Discussion started by: Leojhose
2 Replies
Login or Register to Ask a Question