Sponsored Content
Top Forums UNIX for Advanced & Expert Users capture data from matched string/line Post 302506649 by sumoka on Monday 21st of March 2011 01:15:53 PM
Old 03-21-2011
capture data from matched string/line

Hi,

I have a query as follows :

suppose I am matching a string in a file say "start from here"
and I want to pick up 'n' number of lines () from the matched string. Is there any way to do that ?

1) going forward I want to do this for every match for the above string
2) or limit this to only 1 occurrence/ 'n' occurences

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to display nth line before the string is matched.

All, Is there any way out to display the nth line before the string is matched ??? Eg : If i have a file which has the following contents and if i want to get the 3rd line before the string is matched a b c d e f if i give the input as f and lines before the match as 3 then it should... (5 Replies)
Discussion started by: helper
5 Replies

2. Shell Programming and Scripting

Capture two set of data to same line...simple

I would like to capture output from two commands to a test file on the same line... I want to get a file with all Applications and the Version of it...here are the two commands I use to get the output. To get Application list I use ls -1 /Applications/ |grep .app >>... (3 Replies)
Discussion started by: elbombillo
3 Replies

3. Shell Programming and Scripting

save every line in log file with matched string

i have been doing this script to match every line in a current log file (access_log) with strings that i list from a path (consist of 100 of user's name ex: meggae ).. and then make a directory of every string from the text file (/path/meggae/) --->if it matched.. then print every line from the... (3 Replies)
Discussion started by: meggae
3 Replies

4. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

5. Shell Programming and Scripting

Help required on joining one line above & below to the pattern matched string line.

Hi Experts, Help needed on joining one line above & below to the pattern matched string line. The input file, required output is mentioned below Input file ABCD DEFG5 42.0.1-63.38.31 KKKK iokl IP Connection Available ABCD DEFG5 42.0.1-63.38.31 ... (7 Replies)
Discussion started by: krao
7 Replies

6. Shell Programming and Scripting

Print only matched string instead of entire line

Hi, I have a file whose lines are something like Tchampionspsq^@~^@^^^A^@^@^@^A^A^Aÿð^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^?ð^@^@^@^@^@^@^@?ð^@^@^@^@^@^@pppsq^@~^@#@^@^@^@^@^@^Hw^H^@^@^@^K^@^@^@^@xp^At^@^FTtime2psq^@ ~^@^^^A^@^@^@^B^A I need to extract all words matching T*psq from the file. Thing is... (4 Replies)
Discussion started by: shekhar2010us
4 Replies

7. Shell Programming and Scripting

Capture string contained on a line?

Hello All, I'm working on a script that runs the wget command on a list of IP Address in order to capture the data at that address' index.html. That part works fine to get the HTML code at that address but the data I'm trying to pull out is on a line containing a BUNCH of code for an HTML... (4 Replies)
Discussion started by: mrm5102
4 Replies

8. UNIX for Dummies Questions & Answers

Commenting a line matched with a specific string in a file

Hi, I would like to comment a line that matched a string "sreenivas" in a file without opening it. Thanks in advance. Regards, Sreenivas (3 Replies)
Discussion started by: raosr020
3 Replies

9. Shell Programming and Scripting

How to capture string below a line?

Hi, I need to collect IP address of all servers (more than 300). One way is put it in for loop and run nslookup for that servers list, but there are multiple fields in output. (tty/dev/pts/13): bash: 1011 > nslookup vplssor04 Server: 10.58.115.34 Address: 10.58.115.34#53 Name: ... (7 Replies)
Discussion started by: solaris_1977
7 Replies

10. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 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 it copies string to the variable whose name is given by varName. (Reg- ular expression matching is described in the re_syntax reference page.) If there is a match, then while copying string to varName the por- tion 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 portion 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 regexp 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 METASYNTAX, below). -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 METASYNTAX, below). -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 METASYNTAX, below). -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 METASYNTAX, below). -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 -. The command returns a count of the number of matching ranges that were found and replaced. 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 01:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy