Row to column converter using Awk or grep?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Row to column converter using Awk or grep?
# 1  
Old 11-06-2008
Row to column converter using Awk or grep?

Hello,

Can someone please help me on this.Smilie
I have a file which has more than 1 million lines (XML file).

What I need is:

Search for "abcd" in the input file > output the result into a output.txt (colloum1)

Search for "efghi" in the input file > output the result in to a output.txt (coluun2)

Search for "zzzz" in the input file > output the result in to a output.txt (coluun3)

Thanks in advance
# 2  
Old 11-06-2008
by the way there is
N input files but there should be only
1 output file
# 3  
Old 11-06-2008
What defines a "column". Is the output to be in XML as well? Anyway, see "info paste" (since the man page might be a bit deficient). Essentially:
Code:
grep abcd file1 >output1.txt
grep efghi file1 >output2.txt
grep zzzz file1 >output3.txt
paste output[123].txt >output.txt
rm output[123].txt

# 4  
Old 11-06-2008
Hammer & Screwdriver

Can you grep on each of the three inputs to temp files, called temp1 temp2 temp3
And then use the paste command to put them into columns
Code:
paste temp1 temp2 temp3 >finalfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to do column to row in awk

Hi , Can anyone help me suggesting - how to do the below trick with awk Input 120 130 140 210 310 410 645 729 800 Output 120 130 140 (6 Replies)
Discussion started by: Indra2011
6 Replies

2. Shell Programming and Scripting

awk script row to column

Hi.. I have data : Report testing1 20180419 08:00 Report testing2 20180419 07:35 Report testing 20180419 08:01 Source = data1 Report testing4 20180419 08:05 Source = data1 Report testing5 20180419 08:10 Source = data2 Report testing6 20180419 08:01 Report testing7 20180419 08:19... (4 Replies)
Discussion started by: buncit8
4 Replies

3. Shell Programming and Scripting

Search/grep on row and column wise

Hello, I have a comma seperate metadata as follows: CITY ,COUNTY,STATE,COUNTRY NEW_YORK,NYC ,NY ,USA NEWARK ,ESSEX ,NJ ,USA CHICAGO ,COOK ,IL ,USA SEATTLE ,MINER ,WA ,USA In my process, I get two key values ie CITY NAME (can be one of the... (7 Replies)
Discussion started by: calredd
7 Replies

4. Shell Programming and Scripting

Transpose column to row - awk

Hi there, I have a small csv file example below: source,cu_001,cu_001_volume,cu_001_mass,cu_002,cu_002_volume,cu_002_mass,cu_003,cu_003_volume,cu_003_mass ja116,1.33,3024000,9374400,1.54,3026200,9375123,1.98,3028000,9385512 I want to transpose columns to rows starting at the second... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

5. Shell Programming and Scripting

Grep the column for a row

I have a problem caught and need to discuss with all you guys. I have a file containing a rows which are separated by “~” For eg. Server~321~UP~Linux~Member 121213~5778~Down~Unix~Provider I want to use the grep which search the row on the basis of columns like the grep... (6 Replies)
Discussion started by: adisky123
6 Replies

6. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

7. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

8. Shell Programming and Scripting

awk: Transpose csv row to column.

Hello, am I new to awk, and I am tryint to: INPUT FILE: "73423555","73423556","73423557","73423558","73423559" OUTPUT FILE: 73423555 73423556 73423557 73423558 73423559 My useless code so far: #!/bin/awk -F ',' BEGIN { i=0; } (8 Replies)
Discussion started by: drbiloukos
8 Replies

9. UNIX for Dummies Questions & Answers

awk question row into column

I have a csv file: test1.csv with 26 columns Sample: Data collected Comp1,,,,,,,,,,,,,,,,,,,,,,,,,Average Number of Arrivals with non Zero,0,0,0,0,0,0,0,0,0,...,0 %Utilization,0.1,0.23,0.14,...,0.36 Data collected Comp2,,,,,,,,,,,,,,,,,,,,,,,,,Average Number of Arrivals with non... (2 Replies)
Discussion started by: calitiggr
2 Replies

10. Shell Programming and Scripting

Get value of last row and 6 column from awk

I want to get value of last row and 6 column from awk. Below is the format of my file. And RED one is my desired value. Actaully this stats usally update after every 1 hour so i want that every time i run the script i get the latest value. Ending time - 01:00:58 HOURLY CALL ATTEMPTS... (4 Replies)
Discussion started by: wakhan
4 Replies
Login or Register to Ask a Question