Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Difference between space and [[:space:]] in regular expression Post 302837235 by bobbygsk on Thursday 25th of July 2013 11:35:51 AM
Old 07-25-2013
Difference between space and [[:space:]] in regular expression

May I know the difference between space in keyboard and [[:space:]] in regular expression

I entered the following
Code:
find . -type f -print | xargs grep -n 'dt=' | cut -d":" -f3 | sed 's/^ *dt=/dt=/g'
After "^" there is a space.
and the result is...
dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d`
dt=`date +%Y%m%d`
        dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`
dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`
dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`
        dt=`date +%Y%m%d%H%M%S`

and when i used [[:space:]]

Code:
find . -type f -print | xargs grep -n 'dt=' | cut -d":" -f3 | sed 's/^[[:space:]]*dt=/dt=/g'
and the I got the expected result
dt=`date +%d%m%y_%H%M%S`
dt=`date +%d%m%y_%H%M%S`
dt=`date +%d%m%y_%H%M%S`
dt=`date +%d%m%y_%H%M%S`

---------- Post updated at 11:35 AM ---------- Previous update was at 11:31 AM ----------

By including space it did trimmed spaces for few of them.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expression For Space

Hi all, I want a regular expression that will check for the space. I mean, it should accept everything but no space should be there in the variable. e.g. var1="aaaa" >>> OK var2='aaa vv' >> Not OK So it should not validate the second variable. Please help. Thanks in Advance.... (3 Replies)
Discussion started by: patelamit009
3 Replies

2. UNIX for Advanced & Expert Users

wake up user space thread from kernel space ISR

Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt. Except for sending a real-time signal, is it possible to use a semaphore? I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies

3. Red Hat

add lvm space from a regular partition

Hi, I have red hat enterprise 4. I would like to add more space on my lvm from the first partition that is not lvm type. Here's the config # fdisk -l Disk /dev/sda: 73.4 GB, 73406611456 bytes 255 heads, 63 sectors/track, 8924 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes... (6 Replies)
Discussion started by: itik
6 Replies

4. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

5. Shell Programming and Scripting

What's the difference between \d , [:digit:], and [0-9] in regular expression ?

Hello, $ ] && echo "ok" || echo "error"; error $ ]] && echo "ok" || echo "error"; error $ ]] && echo "ok" || echo "error"; ok $ It seems that \d , , and are not the same.According to the regular expression reference, \d , , and have the same meaning, which represent a digit, but why... (8 Replies)
Discussion started by: 915086731
8 Replies

6. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

7. Shell Programming and Scripting

ignore space regular expression

I just wrote a modsecurity rule that blocks execution on "cat /etc/passwd" from webshell. But when I use cat /etc/passwd it works. Ie when I add space after cat. What I need is a regular expression to ignore additional space than the first single space after cat. (2 Replies)
Discussion started by: anil510
2 Replies

8. Fedora

Need to incrwase PHYSICAL VOLUME space on hard drive with free space on it

Hi, I run Fedora 17. I created a physical volume of 30GB on a disk with 60GB of space so there is 30GB of free space. On the physical volume, I created my volume group and logical volumes. I assigned all the space in the physical volume to my volume group. I need to add the 30GB of free space... (1 Reply)
Discussion started by: mojoman
1 Replies

9. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

10. Shell Programming and Scripting

Replacing Multiple spaces with a single space but excluding few regular expressions

Hi All. Attached are two files. I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt " I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line. But in two... (3 Replies)
Discussion started by: sparks
3 Replies
AUSEARCH_ADD_REGEX(3)						  Linux Audit API					     AUSEARCH_ADD_REGEX(3)

NAME
ausearch_add_regex - use regular expression search rule SYNOPSIS
#include <auparse.h> int ausearch_add_regex(auparse_state_t *au, const char *expr); DESCRIPTION
ausearch_add_regex adds one search condition based on a regular expression to the current audit search expression. The search conditions can then be used to scan logs, files, or buffers for something of interest. The regular expression follows the posix extended regular expression conventions, and is matched against the full record (without interpreting field values). If an existing search expression E is already defined, this function replaces it by (E && this_regexp). RETURN VALUE
Returns -1 if an error occurs; otherwise, 0 for success. SEE ALSO
ausearch_add_expression(3), ausearch_add_item(3), ausearch_clear(3), ausearch_next_event(3), regcomp(3). AUTHOR
Steve Grubb Red Hat Sept 2007 AUSEARCH_ADD_REGEX(3)
All times are GMT -4. The time now is 02:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy