Extract all text between the same matching string from a given column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract all text between the same matching string from a given column
# 1  
Old 04-12-2015
Extract all text between the same matching string from a given column

Hello All,
I have an input sample data like below (In actual I have many columns and few million rows).
Code:
Column1,Column2
4,2
1,5
Hello,4
1,4
Hello,2
3,5
Hello,8
4,5

Need the output (using awk and/or sed preferably) like below. Here I need all the lines between 2 matching strings(inclusive) from a particular column (in this case, column 1) but the matching strings are the same ones "Hello".
Also preserve the header too.

Code:
Column1,Column2
Hello,4
1,4
Hello,2
3,5
Hello,8

Thanks
Sidda
# 2  
Old 04-12-2015
What operating system are you using?

What shell are you using?

How is the column to be searched specified?

From your given requirements, why isn't the output the same as the input? The "4" in column 1 on line 2 and the "4" in column 1 on line 9 appear to me to be identical strings; so why aren't they and all lines between them included in the output? Aren't the "4"s matching strings? Aren't the "4"s the same?

What have you tried to solve this problem?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I extract XML block around matching search string?

I want to extract XML block surrounding search string Ex: print XML block for string "myapp1-ear" surrounded by "<application> .. </application>" Input XML: <?xml version="1.0" encoding="UTF-8"?> <deployment-request> <requestor> <first-name>kchinnam</first-name> ... (16 Replies)
Discussion started by: kchinnam
16 Replies

2. Shell Programming and Scripting

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

3. Shell Programming and Scripting

Column string matching in awk

Hello, I want pick up rows from input with conditions: 1) col2 is 2 replicate of col1 joint with "/" 2) col3 is a joint string as replicate of each side of the "/" symbol 3) col2 not equal to col3 input: TG TG/TG TG/TGG C C/C C/CG C C/G CA/CA C C/C CA/CA AG AG/AG... (3 Replies)
Discussion started by: yifangt
3 Replies

4. Shell Programming and Scripting

Extract First and matching word from string in UNIX

Thank you (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

5. Shell Programming and Scripting

How to extract text from STRING to end of line?

Hi I have a very large data file with several hundred columns and millions of lines. The important data is in the last set of columns with variable numbers of tab delimited fields in front of it on each line. Im currently trying sed to get the data out - I want anything beetween :RES and... (4 Replies)
Discussion started by: Manchesterpaul
4 Replies

6. Shell Programming and Scripting

Sum of column matching pattern/string

Hi All, I have the following output file created as a result of one script called pattern_daily.log $ cat pattern_daily.log Approved|2|Wed, Oct 24, 2012 11:21:09 AM Declined|1|Wed, Oct 24, 2012 11:21:15 AM Approved|2|Wed, Oct 24, 2012 11:24:08 AM Declined|1|Wed, Oct 24, 2012 11:24:18 AM... (4 Replies)
Discussion started by: Gem_In_I
4 Replies

7. Shell Programming and Scripting

Extract text from string

Dear community, I know, this is very stupid question, but I'm scratching my head to find a solution. I have a variable like this: var=" INFO : ABCDEFG"Now I need to remove the leading spaces and output the result like: echo "FIELD1 ; FIELD2 ; $RESULT ; FIELD4" ... (17 Replies)
Discussion started by: Lord Spectre
17 Replies

8. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

9. Shell Programming and Scripting

how to extract a paticular string from the text file with awk.

hello forum members I have txt file which consists the following information. Server: abababa.xyz.ap.mxmx.com Address: 111.143.211.202 Name: rmxd.ipc.ap.mxmx.com Address: 144.111.99.9 from the abovefile i have to extract only string "rmxd.ipc.ap.mxmx.com" through awk command.... (1 Reply)
Discussion started by: rajkumar_g
1 Replies

10. Shell Programming and Scripting

How to extract text from string using regular expressions

Hi, I'm trying to use sed to extract some text and assign it to a variable. Can anyone provide me with some help? it would be much appreciated! I"m looking to extract for example: filename=/output/R34/2005_13_R34_C1042S_T83_CRFTXT_20081015.txt I'm trying to extract the 1042... (9 Replies)
Discussion started by: jtung
9 Replies
Login or Register to Ask a Question