LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-21-2010, 05:18 PM   #31
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454

Quote:
Originally Posted by suse_nerd View Post
Care to give me a little more guidance? I am not that proficient at regex or perl.
I got that I need to do something like this
Code:
$header='~m/^.{8}(.{8})(.{20})(.{8})(.{4})';
$body='(.{8})(.{20})(.{8})(.{4})';
$foot='{2}';
But how to put this into a loop I am not sure. Also still don't really know what you mean by $N. Do you mean the nth ($N) character I split?

How do you detect the end footer? Look ahead by one character and see if it is a $?
By $N I mean $1, $2, $3, etc you've already used.

I do not understand why you need a loop - every line which comes you split into chunks using all those $N variables. You are already doing this, don't you ?

Sorry, but being able to match a character literally is a very basic knowledge, and the tutorial I suggested to read really has this info - somewhere in the beginning.

Your $header, $body, $foot code doesn't make sense to me. Do you understand how the $N variables work ? If not, it's described in the already suggested tutorial.
 
Old 04-21-2010, 09:17 PM   #32
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Here is an alternative:
Code:
#!/usr/bin/awk -f

BEGIN{
		FS=""
		codel=8
		batchl=20
		expiryl=8
		quantityl=4
		start=1
}

{
		gsub(/\$/,"")
		header=gensub(/[^A-Z]*/,"","g")
		gsub(header,"")
		
		print header
		for(i=0;i<(NF/40);i++)
		{
			code = substr($0,start,codel)
			batch = substr($0,(start += codel),batchl)
			expiry = substr($0,(start += batchl),expiryl)
			quantity = substr($0,(start += expiryl),quantityl)
			start += quantityl

			printf "%d,%d,%d,%d\n",code,batch,expiry,quantity
		}
}
 
Old 04-22-2010, 02:52 AM   #33
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Sergei Steshenko View Post
By $N I mean $1, $2, $3, etc you've already used.

I do not understand why you need a loop - every line which comes you split into chunks using all those $N variables. You are already doing this, don't you ?

Sorry, but being able to match a character literally is a very basic knowledge, and the tutorial I suggested to read really has this info - somewhere in the beginning.

Your $header, $body, $foot code doesn't make sense to me. Do you understand how the $N variables work ? If not, it's described in the already suggested tutorial.
It's not every line though - it's only a single line.
I can do it by having 80+ $N variables, yes. That works!
 
Old 04-22-2010, 04:29 AM   #34
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Can I redirect the output to a file with that?
It works if I already have the barcode scanned into a file, I can just use the input and output parameters but what if i scan the barcode directly, it takes the input fine and outputs the fine also, but only to STDOUT

Last edited by suse_nerd; 04-22-2010 at 04:51 AM.
 
Old 04-22-2010, 06:29 AM   #35
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
I am not sure if you are talking to me or Sergei but in mine you can either redirect on the command line or at the print points in the code.

eg. the command line would look like:
Code:
./script input_file > output_file
 
Old 04-22-2010, 07:39 AM   #36
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
I am not sure if you are talking to me or Sergei but in mine you can either redirect on the command line or at the print points in the code.

eg. the command line would look like:
Code:
./script input_file > output_file
Yes thanks, I got tht to work. But if i just run the script, it waits for input. I wanted to just scan the barcode with the handheld scanner and have it either prompt for a file name or let me do something like

Code:
./script > output_file
 
Old 04-22-2010, 08:02 AM   #37
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
The script is waiting for a filename as it uses this to run its changes over, so yes without one it will wait.
When you run the barcode scanner normally, how does it pick the file to save into?
 
Old 04-22-2010, 08:25 AM   #38
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
The script is waiting for a filename as it uses this to run its changes over, so yes without one it will wait.
When you run the barcode scanner normally, how does it pick the file to save into?
It just outputs like a keyboard, it doesn't pick the file at all.
 
Old 04-22-2010, 09:40 PM   #39
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Where does it output to?
 
Old 04-23-2010, 08:22 AM   #40
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
Where does it output to?

Hi Grail - the scanner just functions like a keyboard wedge, it just works like you were typing the data in manually.
 
Old 04-23-2010, 08:59 AM   #41
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Ok, we are missing each other here. If you were at your desktop with no applications open and started typing, generally nothing
would happen unless you hit specific key combinations.
However, if you had a terminal or editor open, then what you typed would appear in those applications.

So, if I plug your scanner into the computer and scan a barcode, would my data go anywhere or does it also require the terminal/editor to be opened
first? Or does it simply send the data straight to a file?
 
Old 04-25-2010, 10:54 AM   #42
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
Ok, we are missing each other here. If you were at your desktop with no applications open and started typing, generally nothing
would happen unless you hit specific key combinations.
However, if you had a terminal or editor open, then what you typed would appear in those applications.

So, if I plug your scanner into the computer and scan a barcode, would my data go anywhere or does it also require the terminal/editor to be opened
first? Or does it simply send the data straight to a file?
Well I would open notepad/kwrite and it would appear directly in kwrite/notepad just as if you were typing. Likewise if you had cmd/shell open it would appear at the command prompt as if you were typing a command. Data won't go to a file unless you press save or pipe it manually into an echo command e.g.
type echo "
scan barcode
type " >> file
 
Old 05-16-2010, 12:13 AM   #43
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Sorry I haven't gotten back to you on this one

I have been busy, but I do have an option although not necessarily very automated.
If you type the following:
Code:
./script > output_file
This will wait for input. So now you can scan using the reader and this will be entered.
If you hit enter after last scan and then the key combination - ctrl+d
This will now pass whatever has been scanned into the script and then into the file.

Sorry I cannot think of a more automated way. Hopefully someone else will see and suggest something, but for now this should work.
 
Old 03-10-2015, 11:04 PM   #44
jacoblee
LQ Newbie
 
Registered: Mar 2015
Posts: 2

Rep: Reputation: Disabled
Not sure if this would be the correct placement of this thread, but seen the question asked before in here.

I recently found the TCPDF library to generate PDF with PHP.

A method to generate 2D barcode is also included.

I want to use this feature to generate PDF417 ad Aztec barcode without generating a PDF file. (Like saving it to a file (PMG. SVG, etc) I looked at the included files to see if I can find the code I need, but I didn't find anything.

On the website, akk the exemples are based on the fact that people want a PDF file... I jsut want the image

Any suggestion? I don't want to pay 400$ for a barcode.
 
  


Reply

Tags
awk, barcode, barcodes, bash, decode, perl, process, processing, script, sed



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Looking for experience to make a script more efficient. aSingularity Programming 7 04-03-2010 01:41 AM
Next step to make this script more efficient...? redlinuxxx Programming 2 10-01-2009 09:42 AM
parsing script sthompson Linux - Server 14 06-10-2008 09:39 AM
LXer: Memory-efficient XML parsing in PHP with XMLReader LXer Syndicated Linux News 0 02-04-2007 05:33 PM
Help with Text Parsing Script NiallC Programming 6 06-24-2006 03:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration