Sponsored Content
Full Discussion: grep and cut problem
Top Forums UNIX for Dummies Questions & Answers grep and cut problem Post 302217930 by zaxxon on Thursday 24th of July 2008 12:37:11 AM
Old 07-24-2008
I guess I live in another timezone and when work is over, I go home and usually don't look into here anymore. That's why I didn't answer that fast Smilie Can you post the pm question here please? I will describe the syntax soon as edit in this post here.

EDIT:

Code:
sed 's/.*<TAG1>\([^>]*\)<\/TAG1>.*/\1/g'

s = substitution
/ = start of the pattern
. = any character
* = zero or as many of the former character
\( = escaped starting bracket of the group I want to extract
[ = starting squared bracket of a group of characters
^ = inside the squared bracket means "not/none" of the following, in this case as long as no > shows up
] = ending the group
* = zero or as many of the former character, in this case as many as it is no >
\) = escaped bracket to end the group definition
\/ = just escaping the slash of that end tag
.* = zero or as many of any character (you know that by know already Smilie )
/ = here ends the pattern I want to find and starts that, through what I want to substitute
\1 = print out the 1st group I defined inside the \( \) escaped curled brackets
/ = end of the substitution input
g = globally, do it on the whole line of input


Best search the web for sites that explain regular expressions (reg exp) or get that nice awk&sed book from O'Reilly which is worth it, the small reference book and/or the "bigger" one.

Last edited by zaxxon; 07-24-2008 at 01:48 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep and cut....

hi, i have a simple question: in hpux 11i; this cmd : cat mailtest |grep sekar >test1 gives the output file with the name test1. i want to remove the line which contains the "sekar" and put the result in the new file.... what is the command for that?.. (2 Replies)
Discussion started by: sekar sundaram
2 Replies

2. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

3. Shell Programming and Scripting

tail, grep and cut

Hello all, I have some weird problem that kinda baffles me. Say I have the following test file: claudia:~/tmp$ cat testfile.txt This is a test line This is the second test line And yeah, this is the third test line Then say I want to tail the file, grep for the word "third" then... (7 Replies)
Discussion started by: sylaan
7 Replies

4. Shell Programming and Scripting

Using grep and cut within awk

Hi My input file looks like as follows: say a.txt "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd" "aaaa cc","224 AW","ss... (5 Replies)
Discussion started by: bittoo
5 Replies

5. Shell Programming and Scripting

!!EMERGENCY!! - GREP/CUT to array

hi people, I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this? Ex: 11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa 21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa 31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa 41aaa 42000 43aaa... (5 Replies)
Discussion started by: gc_sw
5 Replies

6. Shell Programming and Scripting

Problem in getting data from a loop using grep and cut

The script is following : for each_rec in <file_name> do count=`cut -c -2 ${each_rec} | grep "45"` echo ${count} if ] then amount=`cut -c 24-35 ${each_rec}` echo ${amount} else echo "failed" fi done And the file looks like below : ... (4 Replies)
Discussion started by: mady135
4 Replies

7. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

8. Shell Programming and Scripting

grep with cut option??

This is my command-line code in my script, passwd=`grep $passwd $userfile | cut -f2 -d: login_users > retrieve` the cut -f2 -d: login_users > retrieve searches and prints the whole column two. what I need is one of the items in the column two only.. what option can I add to my cut... (2 Replies)
Discussion started by: jenimesh19
2 Replies

9. Shell Programming and Scripting

Cut Lines using grep

Hi, I have a SQL script with "create table" and "alter table" statements and I want to cut all the alter table statements from original file (A) and move it to a different file (B). Can you please me the option. Thanks a lot for your time. (3 Replies)
Discussion started by: bhupinder08
3 Replies

10. Shell Programming and Scripting

Problem with GREP + CUT - script for automatic update of STEAM GAME AR

Hello, I have a problem with the /etc/rc.d/init.d script to automatically update STEAM GAME ARK. I've converted 3 scripts into one, but something does not work correctly ... The problem is in the file latestavailableupdate.txt / line 36/39. It think the problem is with script, it wrongly... (2 Replies)
Discussion started by: kshishu
2 Replies
regsub(n)						       Tcl Built-In Commands							 regsub(n)

__________________________________________________________________________________________________________________________________________________

NAME
regsub - Perform substitutions based on regular expression pattern matching SYNOPSIS
regsub ?switches? exp string subSpec ?varName? | _________________________________________________________________ DESCRIPTION
This command matches the regular expression exp against string, and either copies string to the variable whose name is given by varName or | returns string if varName is not present. (Regular expression matching is described in the re_syntax reference page.) If there is a match, then while copying string to varName (or to the result of this command if varName is not present) the portion of string that matched | exp is replaced with subSpec. If subSpec contains a ``&'' or ``'', then it is replaced in the substitution with the portion of string that matched exp. If subSpec contains a `` '', where n is a digit between 1 and 9, then it is replaced in the substitution with the por- tion of string that matched the n-th parenthesized subexpression of exp. Additional backslashes may be used in subSpec to prevent special interpretation of ``&'' or ``'' or `` '' or backslash. The use of backslashes in subSpec tends to interact badly with the Tcl parser's use of backslashes, so it's generally safest to enclose subSpec in braces if it includes backslashes. If the initial arguments to regsub start with - then they are treated as switches. The following switches are currently supported: -all All ranges in string that match exp are found and substitution is performed for each of these ranges. Without this switch only the first matching range is found and substituted. If -all is specified, then ``&'' and `` '' sequences are handled for each substitution using the information from the corresponding match. -expanded Enables use of the expanded regular expression syntax where whitespace and comments are ignored. This is the same as speci- fying the (?x) embedded option (see the re_syntax manual page). -line Enables newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning. With this flag, `[^' bracket expressions and `.' never match newline, `^' matches an empty string after any newline in addition to its normal function, and `$' matches an empty string before any newline in addition to its normal function. This flag is equivalent to specifying both -linestop and -lineanchor, or the (?n) embedded option (see the re_syntax manual page). -linestop Changes the behavior of `[^' bracket expressions and `.' so that they stop at newlines. This is the same as specifying the (?p) embedded option (see the re_syntax manual page). -lineanchor Changes the behavior of `^' and `$' (the ``anchors'') so they match the beginning and end of a line respectively. This is the same as specifying the (?w) embedded option (see the re_syntax manual page). -nocase Upper-case characters in string will be converted to lower-case before matching against exp; however, substitutions specified by subSpec use the original unconverted form of string. -start index Specifies a character index offset into the string to start matching the regular expression at. When using this switch, `^' will not match the beginning of the line, and A will still match the start of the string at index. index will be constrained to the bounds of the input string. -- Marks the end of switches. The argument following this one will be treated as exp even if it starts with a -. If varName is supplied, the command returns a count of the number of matching ranges that were found and replaced, otherwise the string | after replacement is returned. See the manual entry for regexp for details on the interpretation of regular expressions. SEE ALSO
regexp(n), re_syntax(n) KEYWORDS
match, pattern, regular expression, substitute Tcl 8.3 regsub(n)
All times are GMT -4. The time now is 09:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy