...Why are there so many different types of regular expression?
That shouldn't be so surprising. They are just different methods of arriving at the same solution. Just as there are different routes to go from point A to point B.
The regex in the first awk solution used a character class with the repetition quantifier "+".
There's a blank space and a tab character in there which means that this regex searches for one or more occurrences, from the beginning, of either a space or tab character (or any combination of both). The sub function substitutes those with a zero-length string.
I think "\t" for the actual tab character should work; at least it does for gawk:
The "+" repetition quantifier is an Extended Regular Expression (ERE). Gnu sed allows it, but the sed binaries in most Unix systems do not. So the other type of regex used in the sed solution was this -
The bracket repetition operator is for finer control over repetition. "+" means one or more - there's no limit for "more". Whereas {m,n} means at least m at the most n repetitions. Further, {m,} means at least m repetitions - there's no upper limit here. So {1,} becomes equivalent to "+", which is why the sed solution works more or less the same. (It doesn't take care of tab characters though).
Quote:
...Perl regular expression is not similar to sed regular expression.
Perl is a different beast altogether. All the above concepts, BREs as well as EREs, are for POSIX regexes. Perl, on the other hand, started off by implementing Henry Spencer's regular expression library. It's regex syntax is richer, more consistent and more extensive than those of POSIX compliant regexes.
The following command works echo "some text with spaces" | sh -c 'sed -e 's/t//g''But this doesn't and should echo "some text with spaces" | sh -c 'sed -e 's/ //g''Any ideas? (3 Replies)
Greetings All,
I would like to find all occurences of a pattern and delete a substring from the all matching lines EXCEPT the first. For example:
1234::group:user1,user2,user3,blah1,blah2,blah3
2222::othergroup:user9,user8
4444::othergroup2:user3,blah,blah,user1
1234::group3:user5,user1
... (11 Replies)
I have a variable
I want to remove the spaces in between.
The output should be
How can this be done
Any help will be appreciated. Thanks in advance (1 Reply)
Hi, I'm writing a ksh script and trying to use an awk / sed / or perl one-liner to remove the last 4 characters of a line in a file if it begins with a period.
Here is the contents of the file... the column in which I want to remove the last 4 characters is the last column. ($6 in awk). I've... (10 Replies)
Hi all,
i am getting count from oracle 11g by spooling it to a file.
Now there are some newline characters and blank spaces i need to remove these.
pl provide me a awk/sed solution.
the spooled file is attached.
i tried this.. but not getting req o/p (6 Replies)
if the answer is obvious, sorry, I'm new here.
anyway, I'm using tr to encrypt with rot-13:
echo `cat $script | tr 'a-zA-Z' 'n-za-mN-ZA-M'` > $script
it works, but it removes any consecutive spaces so that there is just one space between words. I've had this problem before while using sed to... (5 Replies)
How to delete ending/trailing spaces using awk,sed,perl?
Input:(each line has extra spaces at the end)
3456 565
3 7
35 878
Expected output:
3456 565
3 7
35 878 (5 Replies)
Hello and thx for reading this
I'm using sed to remove only the leading spaces in a file
bash-280R# cat foofile
some text
some text
some text
some text
some text
bash-280R#
bash-280R# sed 's/^ *//' foofile > foofile.use
bash-280R# cat foofile.use
some text
some text
some text... (6 Replies)
Hello,
I have the following to remove spaces from beginning and end of a string.
infile=`echo "$infilename" | sed 's/^ *//;s/ *$//`
How do I modify the above code to remove spaces from beginning, end and in the middle of the string also.
ex:
... (4 Replies)