Sponsored Content
Top Forums Shell Programming and Scripting Need some help with a regex if loop problem Post 302442966 by linuxkid on Friday 6th of August 2010 05:25:07 AM
Old 08-06-2010
Need some help with a regex if loop problem

Need some help with a regex if loop problem.
File1:
Code:
2323
3232
4230
3230
4340
4343
233
32320

I want to print "Zero" if the number ends with a zero, but print "number" if it does not!
Code:
#!/bin/bash
/usr/bin/nawk '{
if ($1 ==/[0-9]+0\b/){
 print "Zero"}
else{
 print "number"}
}' File1

this code just prints out "Number" for each line! Help!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep regex problem

Hi, I am trying to do something with grep, but for some reason I just can't get it to to work. I am looking for find a match in the second field, the length must be 10 characters and end with 'abc'. The file is in this format: <int><tab><field2> I've tried a few patterns, some work,... (2 Replies)
Discussion started by: iceman
2 Replies

2. Shell Programming and Scripting

regex problem

Hi, #!/usr/bin/perl -w my $timestamp; my $line = "Fri May 29 18:29:57.357 2009 Morocco Standard Time INFO: pid 3216 tid 1724: 170: 132192: apricocot Native Server: recvd AA_BIN_MSG_VER_CHG"; if ($line =~ /^(.*) INFO: .* recvd AA_BIN_MSG_VER_CHG/) { $timestamp = $1; ... (1 Reply)
Discussion started by: namishtiwari
1 Replies

3. UNIX for Dummies Questions & Answers

regex problem with +

Hi, Can someone tell me why the first regular expression with the + fails to match the input string? SUN /web>echo cat | grep '+' SUN /web>echo cat | grep '' cat I'm running SunOS 5.10 Thanks. Chris (2 Replies)
Discussion started by: che9000
2 Replies

4. Programming

REGEX problem

Hi there, How can we use regex in perl to store the Route Distinguisher (the bold field) and also the underlined and bold lines in the below file? Note: These highlighted pattern is redundant through the whole input file. Basically, we just need to extract these fields at least to store them... (4 Replies)
Discussion started by: omoyne
4 Replies

5. UNIX for Advanced & Expert Users

Sed regex problem

Hi, I tried to extract the time from `date` with sed. (I know it works with `date +%H:%M:%S` as well) I got three solutions of which just one worked. I thought "+" should repeat the previous expression 1 or more times and {n} should repeat the previous expression n times. $ date Thu... (9 Replies)
Discussion started by: thiuda
9 Replies

6. Shell Programming and Scripting

awk regex problem

hi everyone suppose my input file is ABC-12345 ABCD-12345 BCD-123456 i want to search the specific pattern which looks like - in a file so i used this command cat $file | awk ' { if ($0 ~ /-/) { print } }' so it gives me the result as ABCD-12345 BCD-12345 BCD-12345 ... (31 Replies)
Discussion started by: aishsimplesweet
31 Replies

7. Programming

Regex problem

Hi, I am looking for regex to extract following words from text: The word which comes after "Replaced" means Replaced disk Replaced floppy Replaced memory Please suggest the regex for it. Thanks! (4 Replies)
Discussion started by: gunjanamit
4 Replies

8. Shell Programming and Scripting

Failure using regex with awk in 'while read file' loop

I have a file1.txt with several 100k lines, each of which has a column 9 containing one of 60 "label" identifiers. Using an labels.txt file containing a list of labels, I'd like to extract 200 random lines from file1.txt for each of the labels in index.txt. Using a contrived mini-example: $ cat... (8 Replies)
Discussion started by: pathunkathunk
8 Replies

9. Shell Programming and Scripting

REGEX to separate paths by whitespace and do a loop

I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working, I have echo {3} | sed 's/ //g' | while read EACHFILE do ..... But for some reason is only taking always the first path that I... (7 Replies)
Discussion started by: jorgejac
7 Replies

10. Shell Programming and Scripting

Perl Regex problem

Script logs into switches on my list but nothing seems to happen. Following error: tr nope, doesn't (yet) match (?-xism:-]+ ?(?:\(config*\))? ? ?$) du SEEN: Here is code in question: @version_info = $session_obj->cmd('term length 0'); $session_obj->cmd('show int | i... (5 Replies)
Discussion started by: mrlayance
5 Replies
Acme::Brainfuck(3)					User Contributed Perl Documentation					Acme::Brainfuck(3)

NAME
Acme::Brainfuck - Embed Brainfuck in your perl code SYNOPSIS
#!/usr/bin/env perl use Acme::Brainfuck; print 'Hello world!', chr ++++++++++. ; DESCRIPTION
Brainfuck is about the tiniest Turing-complete programming language you can get. A language is Turing-complete if it can model the opera- tions of a Turing machine--an abstract model of a computer defined by the British mathematician Alan Turing in 1936. A Turing machine con- sists only of an endless sequence of memory cells and a pointer to one particular memory cell. Yet it is theoretically capable of perform- ing any computation. With this module, you can embed Brainfuck instructions delimited by whitespace into your perl code. It will be trans- lated into Perl as parsed. Brainfuck has just just 8 instructions (well more in this implementation, see "Extensions to ANSI Brainfuck" below.) which are as follows Instructions + Increment Increase the value of the current memory cell by one. - Decrement Decrease the value of the current memory cell by one. > Forward Move the pointer to the next memory cell. < Back Move the pointer to the previous memory cell. , Input Read a byte from Standard Input and store it in the current memory cell. . Output Write the value of the current memory cell to standard output. [ Loop If the value of the current memory cell is 0, continue to the cell after the next ']'. ] Next Go back to the last previous '['. Extensions to ANSI Brainfuck This implementation has extra instructions available. In order to avoid such terrible bloat, they are only available if you use the ver- bose pragma like so: use Acme::Brainfuck qw/verbose/; The extra instructions are: ~ Reset Resets the pointer to the first memory cell and clear all memory cells. # Peek Prints the values of the memory pointer and the current memory cell to STDERR. See also "Debugging" below. Debugging By using the debug pragma like this: use Acme::Brainfuck qw/debug/; you can dump out the generated perl code. (Caution: it is not pretty.) The key to understanding it is that the memory pointer is repre- sented by $p, and the memory array by @m Therefore the value of the current memory cell is $m[$p]. RETURN VALUE
Each sequence of Brainfuck instructions becomes a Perl block and returns the value of the current memory cell. EXAMPLES
JABH #!/usr/bin/env perl use Acme::Brainfuck; print "Just another "; ++++++[>++++++++++++++++<-]> ++.-- >+++[<++++++>-]<.>[-]+++[<------>-]< +.- +++++++++.--------- ++++++++++++++.-------------- ++++++.------ >+++[<+++++++>-]<.>[-]+++[<------->-]< +++.--- +++++++++++.----------- print " hacker. "; Countdown #!/usr/bin/env perl use strict; use Acme::Brainfuck qw/verbose/; print "Countdown commencing... "; ++++++++++[>+>+<<-] >>+++++++++++++++++++++++++++++++++++++++++++++++<< ++++++++++[>>.-<.<-] print "We have liftoff! "; Reverse #!/usr/bin/env perl use Acme::Brainfuck qw/verbose/; while(1) { print "Say something to Backwards Man and then press enter: "; +[->,----------]< print 'Backwards Man says, "'; [+++++++++++.<]< print "" to you too. "; ~ } Math #!/usr/bin/env perl use Acme::Brainfuck; use strict; use warnings; my $answer = +++[>++++++<-]> ; print "3 * 6 = $answer "; VERSION
1.1.1 Apr 06, 2004 AUTHOR
Jaldhar H. Vyas E<lt>jaldhar@braincells.comE<gt> THANKS
Urban Mueller - The inventor of Brainfuck. Damian Conway - For twisting perl to hitherto unimaginable heights of weirdness. Marco Nippula <http://www.hut.fi/~mnippula/> - Some code in this module comes from his brainfuck.pl Mr. Rock - Who has a nice Brainfuck tutorial at <http://www.cydathria.com/bf/>. Some of the example code comes from there. COPYRIGHT AND LICENSE
Copyright (c) 2004, Consolidated Braincells Inc. Licensed with no warranties under the Crowley Public License: "Do what thou wilt shall be the whole of the license." perl v5.8.3 2004-04-06 Acme::Brainfuck(3)
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy