How to use awk to output such a pattern?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use awk to output such a pattern?
# 1  
Old 02-16-2016
How to use awk to output such a pattern?

Hi all,

I want to output the following pattern in a comma separted format, but am not able to do it.

HTML Code:
Table1.FIND.Value= 124
Data
Data
Data
Data
Data
Table1.FIND.Value =256
Data
Data
Data
Data
Data
The outPut i expect is

HTML Code:
Table1.FIND.Value=124,Data,Data,Data,Data,Data
Table1.FIND.Value=256,Data,Data,Data,Data,Data
I am able to do all in one go with

HTML Code:
awk 'BEGIN{RS="\n";ORS=",";}{print $0}' File
But this outputs everything as one single record with comma separated values.

Not sure how to achieve this.
# 2  
Old 02-16-2016
TrY:
Code:
awk '/FIND\.Value/{if(s)print s; gsub(FS,x); s=$1; next}{s=s "," $1} END{if(s)print s}' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-16-2016
Hello sidnow,

Could you please try following and let me know if this helps.
Code:
awk '{gsub(/= | =/,"=",$0);} /^Table1/ && A{print A;A=$0;next} {;A=A?A OFS $0:$0} END{print A}' OFS=,   Input_file

Output will be as follows.
Code:
Table1.FIND.Value=124,Data,Data,Data,Data,Data
Table1.FIND.Value=256,Data,Data,Data,Data,Data

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 02-16-2016
Another one
Code:
awk '{printf (/FIND\.Value/ ? rs : ",") "%s", $0; rs=RS} END {printf rs}' file

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 02-16-2016
Quote:
Originally Posted by Scrutinizer
TrY:
Code:
awk '/FIND\.Value/{if(s)print s; gsub(FS,x); s=$1; next}{s=s "," $1} END{if(s)print s}' file

Worked like a charm

---------- Post updated at 02:49 PM ---------- Previous update was at 02:49 PM ----------

Quote:
Originally Posted by RavinderSingh13
Hello sidnow,

Could you please try following and let me know if this helps.
Code:
awk '{gsub(/= | =/,"=",$0);} /^Table1/ && A{print A;A=$0;next} {;A=A?A OFS $0:$0} END{print A}' OFS=,   Input_file

Output will be as follows.
Code:
Table1.FIND.Value=124,Data,Data,Data,Data,Data
Table1.FIND.Value=256,Data,Data,Data,Data,Data

Thanks,
R. Singh

This one too.Worked like a charm

---------- Post updated at 02:49 PM ---------- Previous update was at 02:49 PM ----------

Quote:
Originally Posted by MadeInGermany
Another one
Code:
awk '{printf (/FIND\.Value/ ? rs : ",") "%s", $0; rs=RS} END {printf rs}' file

Another one, Worked like a charm
# 6  
Old 02-16-2016
If its always the same number of data:
Code:
paste -sd",,,,,\n" file
Table1.FIND.Value= 124,Data,Data,Data,Data,Data
Table1.FIND.Value =256,Data,Data,Data,Data,Data

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to remove pattern and lines above pattern

In the awk below I am trying to remove all lines above and including the pattern Test or Test2. Each block is seperated by a newline and Test2 also appears in the lines to keep but it will always have additional text after it. The Test to remove will not. The awk executed until the || was added... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

Help! Printing out CSV output from awk Pattern Match

Hi, I need to search for a word using Awk and print out the line the word is in and every line after the search phrase until I hit this #------------. Then I need to send it to a csv file. So basically the input file format is like this:... (1 Reply)
Discussion started by: An0mander
1 Replies

4. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

5. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

6. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

7. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

8. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

9. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

10. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies
Login or Register to Ask a Question