Visit Our UNIX and Linux User Community

awk: process file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk: process file
# 1  
Old 02-04-2010
awk: process file

Hello, i have a file as below:
AAA: 1
BBB: 2
CCC: 3

AAA: 11
BBB: 22
CCC: 33

AAA: 111
BBB: 222
CCC: 333
how to process it by using AWK to this:
1 11 111
2 22 222
3 33 333

thank in advance for your help.

Last edited by 0916981; 02-04-2010 at 05:38 AM.. Reason: editing title
# 2  
Old 02-04-2010
Looks like all you want is to convert columns into rows, right? So if your file is named, try this.
awk '{
 arr[$1]=arr[$1]" "$2
 for ( i in arr) {
  print i,arr[i]

The output is reversed, but I guess that should be fine, right?

Last edited by pludi; 02-04-2010 at 03:17 PM.. Reason: code tags, please...
# 3  
Old 02-04-2010
It worked perfectly. Thank linuxpenguin.

Previous Thread | Next Thread
Test Your Knowledge in Computers #896
Difficulty: Medium
BusyBox, written by Richard Stallman in 1995, is a software suite that provides several Unix utilities in a single executable file.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

2. Shell Programming and Scripting

Using awk to kill a process

Hi Guys I am running a small script to find a process id , ask user if they want to kill the process and then action it Yes or no Here is what i have #/bin/bash ps -l | grep -i $1 | awk '{print "Process id of '$1' is "$4""}' echo "Do you want to kill this process (Y/N)" read action... (10 Replies)
Discussion started by: johnnybananas
10 Replies

3. Shell Programming and Scripting

Process a file for line count using for loop in awk

Hi, I have a file with contents So what I have to do is In short, break the file after every 6 lines and then truncate new line to tab for these 6 lines. I am not able to execute the for loop in awk properly. The idea is something like this: less file| awk '{for .... {if ((nr>=1)... (7 Replies)
Discussion started by: rossi
7 Replies

4. Shell Programming and Scripting

Bash-awk to process thousands of files

Hi to all, I have thousand of files in a folder with names with format "FILE-YYYY-MM-DD-HHMM" for what I want to send the following AWK command awk '/Code.*/' FILE-2014* I'd like to separate all files that have the same date to a folder named with the corresponding date. For example, if I... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

5. UNIX for Advanced & Expert Users

Using awk to read a file and process

I am fairly green using awk so I don't have anything started but what I am trying to do is: I have a file called "contacts" and in the file are 3 fields separate by ;. I want to read each line and send an email script. I have the email function working but just need to know how to setup awk to... (8 Replies)
Discussion started by: ziggy6
8 Replies

6. Shell Programming and Scripting

Need advise to process the file with awk

Hi gurus, i need your advise on how to process this file using awk. i have this file COLA COLB COLC COLD COLE COLF COLG COLH AAAA 86 111 122 133 144 155 266 377 BBBB 70 211 222 233 244 255 266 ... (6 Replies)
Discussion started by: ablanc
6 Replies

7. Shell Programming and Scripting

How to make AWK process an input file many many times?

By "many many times" I mean the times the input file is to be processed is unknown beforehand, it will be known when awk finishes processing the input file for the first time. So my question is: how to start over again from the first record of the input file when AWK finishes processing the... (7 Replies)
Discussion started by: kevintse
7 Replies

8. Shell Programming and Scripting

Need help with a script to process a CSV file using SED and AWK

I get a CSV file every day with 2 columns and multiple rows ex: date1,date2 ( both the fields are varchar fields) This data has to be updated in a table which is being done manually and i want to automate that. 1. I have to select all the data from the prod table( 2 columns { date1,date2}) into... (4 Replies)
Discussion started by: kkb
4 Replies

9. Shell Programming and Scripting

process text file with awk

I have a text file which represent a http packet: header1 haeder2 ..... ..... headern payload I need to count bytes in the payload. How can I get it using awk? Thanks in advance Andrea Musella (2 Replies)
Discussion started by: littleboyblu
2 Replies

Featured Tech Videos