Extract batch based on condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract batch based on condition
# 8  
Old 03-21-2015
Thanks for your reply...but i am not sure if i can put this perl code in my script which is a shell script.
# 9  
Old 03-21-2015
I use perl in shell scripting all the time, you should be fine. Are you getting errors?

Last edited by cmccabe; 03-21-2015 at 03:34 PM..
# 10  
Old 03-21-2015
If for some reason, you really need a way to do this only using shell built-ins, you could try something like the following with any POSIX-conforming shell:
Code:
#!/bin/ksh
IAm="${0##*/}"
Usage() {
	case "$1" in
	(2)	printf "%s: Can't read input_file: %s\n" "$IAm" "$2";;
	(4)	printf '%s: Invalid date in "|T" line: %s\n' "$IAm" "$2";;
	(5)	printf '%s: Invalid ID in ".T" line: %s\n' "$IAm" "$2";;
	(6)	printf '%s: Invalid tag: %s\n' "$IAM" "$2";;
	(7)	printf '%s: Invalid line length: %s\n' "$IAm" "$2";;
	esac >&2
	printf 'Usage: %s input_file output_file\n' "$IAm" >&2
	exit $1
}

[ $# -ne 2 ] && Usage 1
[ ! -r "$1" ] && Usage 2 "$1"
> "$2" || Usage 3 "$2"
while read -r tag data
do	case ${#tag} in
	(2)	case "$tag" in
		("|T")	[ ${#data} -ne 8 ] && Usage 4 "$tag $data"
			out="$tag $data"
			copy=0;;
		(".T")	[ "$data" = '' ] && Usage 5 "$tag"
			if [ $copy -eq 1 ]
			then	printf '%s\n%s %s\n' "$out" "$tag" "$data" > "$2"
			fi;;
		(*)	Usage 6 "$tag $data";;
		esac;;
	(17)	case "$tag" in
		(10000000000000000)
			;;
		(10*)	copy=1;;
		esac
		out=$(printf '%s\n%s' "$out" "$tag");;
	(*)	Usage 7 "$tag $data";;
	esac
done < "$1"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

extract file .jar from package and batch

Thank You to vbe For This Useful Post i want to extract file. jar from package and batch ? (1 Reply)
Discussion started by: moh_abaloo
1 Replies

2. Windows & DOS: Issues & Discussions

Batch file loop and increment value for condition

I am trying to have the below batch file do following two things: 1. only allow the values YES,yes,Y,y, or NO,no,N,n 2. increment the counter %var1 only if answer to question 2 is "y" and not able to get the syntax correct. If %var1%=1 then I am trying to display function :end. Thank you :).... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Copy down based on condition

Hello: I need to copy down some data from the previous record in to the next record based on the below conditions If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then copy the previous records value for positions... (1 Reply)
Discussion started by: techedipro
1 Replies

4. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

5. Shell Programming and Scripting

Help with extract info if fulfill condition required

Input file (4 DATA record shown in this case): DATA AA0110 ACCESSION AA0110 VERSION AA0110 GI:157412239 FEATURES Location/Qualifiers length 1..1170 1..1700 /length="1170" position ... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. Shell Programming and Scripting

ksh: how to extract strings from each line based on a condition

Hi , I'm a newbie.Never worked on Unix before. I want a shell script to perform the following: I want to extract strings from each line ,based on the type of line(Nameline,Subline) and output it to another file.Below is a sample format. 2010-12-21 14:00"1"Nameline"Midterm"First Name:Jane ... (4 Replies)
Discussion started by: angie1234
4 Replies

7. Shell Programming and Scripting

Script to batch pdfjoin based on pdfgrep output

I have a situation in which I'm given a bunch of pdf files which are all single pages with employee ID's on an independent line. I need to collate all of the pages by employee ID. Piecemeal, I can find a particular employee ID by just using pdfgrep. I could also do something like this: find .... (3 Replies)
Discussion started by: nopposan
3 Replies

8. Shell Programming and Scripting

extract xml tag based on condition

Hi All, I have a large xml file of invoices. The file looks like below: <INVOICES> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>1234</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>2345</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME>... (9 Replies)
Discussion started by: angshuman
9 Replies

9. Shell Programming and Scripting

Extract value inside <text> tag for a particular condition.

Hi All! I have obtained following output from a tool "pdftohtml" :: So, my input is as under: <text top="246" left="160" width="84" height="16" font="3">Business purpose</text> <text top="260" left="506" width="220" height="16" font="3">giving the right information and new insights... (3 Replies)
Discussion started by: parshant_bvcoe
3 Replies
Login or Register to Ask a Question