Programming :: Awk Multiple Column Into Single Column?
Jul 15, 2010
I have a multicolumn datas, like
a1 b1 ... f1
a2 b2 ... f2
. . ... .
[code]...
I would like to make a file with all these data in one column, like
a1
a2
.
.
[code]....
Can it be done with awk or some other command? Also, is it possible then do add another column in front of this one with numbers of the lines (for every previous column), like
1 a1
2 a2
. .
. .
[code].....
View 14 Replies
ADVERTISEMENT
May 13, 2011
Have this script which is reading in a series of files, one at a time with while-do-done loop, each file goes through various greps/awk's where this info is then saved to various files for later use. i.e....
Script is being run on Linux Red Hat,
In one of the grep/awk's the output (currently) are 2 columns (min max), i.e....| awk '{print $1, $2}' | sort -u which outputs (e.g.)
The number of "min max" pairs varies from file to file. Want to output a single column of unique numbers from the min max pairs & get the number of them for input to a file...i.e...
Where <PROCESS> is some process/technique that will generate a single column of integers (increment of 1) to pipe into the next one (sort -u)
i.e. (example from above)
Have tried command seq - only works for single pair input i.e.
Is there any command like seq etc which will output a single column based on a input of min max numbers (increment 1) to pipe onwards to next command?
View 4 Replies
View Related
Apr 7, 2011
I need to transpose a file with over a 1000 rows of 5 columns of numbers into a file with a single column of numbers. The numbers are separated by a single space and range from one digit to 5 digits each. I tried using awk, but can only get it to grab one column of numbers.
Input:
1 2 3 4 50
600 7 8 9000 10
11 12000 13 14 15
Desired output:
1
2
3
4
[code]....
Tried using: awk '{split($0,a,""); print $NF}' <filename> and got:
50
10
15
It only grabbed the last number in each row.
View 13 Replies
View Related
Dec 1, 2008
I am writing a script to mine data from my game server logs which are going to mysql. My first question is syslog-ng is sticking $msg into one colum it self, $msg tends to be a long string here are a few examples:
cn name team frag death flags role host.
0 Maik CLA 2 0 0 normal *.70.233.118.
1 lizardncd RVSF -1 3 0 normal
[*.22.247.40] lizardncd fragged Maik.
And they are not always in the same format, How could I parse this data to do something useful, like creating a user stats page with frag counts and flag counts. Should I create a script that runs in a cronjob that parses this data to a new table maybe once a day. Even then the $msg string value is random and I am thinking in terms of awk.
Second. I would like to keep track of what ip's are using what nicknames. Kinda in the sense of and ip associated to a array of names that have been used on that ip address so I can keep track of users. How would this work logically with a mysql db, could a column allow multiple values, then loadable into an array, which then can add, remove, and store to mysql.
View 1 Replies
View Related
Jul 19, 2010
How would i calculate following values.Initial file
10 3
20 4
How would i calculate 3rd column which should be addition of value in 1 and 2nd column.File after calculation
10 3 13
20 4 24
View 14 Replies
View Related
Mar 7, 2010
i use this script to get the time and date of back and fourth transactions for a particular execution id. I use a substr command on the 5th column to to cut the milli seconds off the time value. - otherwise the times would look like 08:30:04.235
grep <executionID> <auditfile> | awk '{ print $1, $2, $3, $4, substr($5,1,8}
FIX -> Mon 3/1/2010 08:30:04
FIX <- Mon 3/1/2010 08:32:36
FIX <- Mon 3/1/2010 08:35:08
[code].....
anyhow - i append two sed commands to further clarify the direction of the message.
awk '{ print $1, $2, $3, $4, substr($5,1,8} | sed -e 's/->/ ->IN/g' | sed -e 's/<-/<-OUT/g'
FIX -> IN Mon 3/1/2010 08:30:04
FIX <- OUT Mon 3/1/2010 08:32:36
[code]....
I tried using an awk gsub () command within the string instead of the two seds, but it did not work:
awk '{ print gsub(/<regex>/, <replace with>,$1), $2, $3, $4, substr($5,1,8}
the sed works ok, but it would be cooler to make the replacement within the awk command:
gsub(/->/,-> IN, $1)
Is there a way where i could replace the value of the $1 column in the awk print string?
View 1 Replies
View Related
Dec 8, 2010
i am new to scriptingi have a file : file.dat with following data
Code: STORAGE PERCENTAGE FLAG:
/storage_01 64% 0
/storage_02 17% 1
[code]...
View 4 Replies
View Related
Jan 13, 2010
Here is the txt file
Code:
I want to use a script to statistic the results like that
I want to know the the same string in the first column and how many different in the second column ?
how awk to write ?
View 7 Replies
View Related
Apr 9, 2010
Problem is simple but I can't figure out how to solve it, I tried any possible way that I know but with no result.I'm using simple perl script with DBI and do select from one table and do update in other table with results from select, but I can't preserve my '' returned from select when doing update. I simply want my '' from first table to be '' in second but postgres makes them real new lines. I tried to escape '' with , '',"",E(I mean E'value here') in front of value that updating but they are always real new lines not '' in new table.
View 2 Replies
View Related
Jul 26, 2010
I am running Linux from a DVD, not installed. I am not good with installing software, but since the DVD cannot be corrupted, I am content to operate this way. Lately, I have been having problems that previously did not occur. When I try to click on the checkbox to get rid of emails, it doesn't register in most cases, or when it does, I am clicking multiple times so it registers twice, meaning it is unchecked again. Even more frustrating is some issues that are affecting my ability to update my business. I am trying to modify spreadsheets (text not calculations).
Whenever I try to click & drag to select something to change, it keeps jumping around to select only some of what I want, something else or some combination of the 2. When I try to copy and paste several fields from 1 column to another, everything from the several fields in the source column ends up together in the last field in the target column. I am also trying to download some images from a website. There is a single column of links to the images. I have to click on the link to get to the image in order to copy it, then back out to continue looking for more links to do the same.
My computer keeps jumping back 2 steps, then forward 2 steps, and sometimes I lose my place in that list. I could deal with it if it were a small number of links, but this is a list of probably close to 20,000 links. Again, i am operating off of a live DVD so this should not be corruptible, but this has just started happening, and has been an issue the last several sessions.
View 14 Replies
View Related
Sep 4, 2010
Code:
#!/bin/bash
ls -lhGg | while read line; do echo "$line"; done | awk ' { print $3" "$6 } '
what i want to do is be able to print column 3 and every column greater then 5. Has to be to the end of the line, since different filenames can have different amounts of words in them and the blank space is the separator. my current code works just fine if the file has no blank space.
View 8 Replies
View Related
Mar 26, 2011
Mar 26 12:32:53 name sshd[3261]: 192.168.1.14Mar 27 12:42:53 name sshd[3262]: 192.168.1.14
how to make this data in output as:
"Mar 26 12:32:53","name","sshd","192.168.1.14"
"Mar 27 12:42:53","name","sshd","192.168.1.14"
View 6 Replies
View Related
Apr 28, 2011
I have a text field that is just list of servers and I need to add the word hostname in front of them... It must be brain fart but I can't think of how to do this. Basically I need this:
server1
server2
server3
To this:
hostname server1
hostname server2
hostname server3
(And I just mean simply the word "hostname")
View 2 Replies
View Related
Feb 24, 2011
I have the following file.
B0 49.2230869 -102.5743868
C 1LPRK 654.90
C 1PREU 3693.90
C 1JRSU 3693.90
[code]....
I need to insert text ABCDEF starting at position 26 if a line starts with C. I need it to look like:
C 1VKNG ABCDEF 3097.00
C 1JLFU ABCDEF 3157.20
C 1MNVL ABCDEF 3346.10
I would prefer to use sed to do this and not perl.
View 14 Replies
View Related
Jul 8, 2011
I am trying to transpose the following row:
x1 x2 x3 x4
into
x1 X2
x3 x4
With tr '''' < file I can select all columns to become separate rows,but as you see x3 and x4 have to be grouped when transposing.Or should I use awk for this one?
View 1 Replies
View Related
Jul 6, 2010
I have a large tab delimited text file, about 17gb. It only has 6 column. On column number 4, it is all numbers. Ranging from 1-1000. I want to count how many times each number occured. So the output I want is in 2 columns, first one is a number, second column is how many times it occured. I tried
head -n 1000 coverage | cut -f 4 | uniq -c
Didn't work for me, the first column returned is not unique.
View 3 Replies
View Related
May 24, 2011
i've been using a awk script to calculate my data... i have 3 files:
file a1.txt:
2
3
4
[code]....
the results were (3.5, 6 and 3) which is pretty easy.. now i want to combine all this into 1 file and each have different columns and called it avg.txt which have something like this in the end:
3.5 6 3
View 1 Replies
View Related
Jan 25, 2010
I'm having problems adding up column totals using arrays. I've got it to add up the row totals and display at the end of the row. Here is my code so far
Code:
#include <stdio.h>
#include <string.h>
const int maxrows=10;
[code]...
What i need it to do is, add up the columns and display it at the bottom of each column similar to how the row totals display
View 2 Replies
View Related
Nov 20, 2010
I have a text file with 4 columns and 18 rows. All are integers. I wish to find the average of first 12 numbers in the third column using 'awk'.
View 8 Replies
View Related
Oct 24, 2010
I have a file which has the output as shown below:
Code:
Teams | matches |Goals | YC | RC
------------------------------------------------------------------------------
Liverpool: | | | |
Gerrard | 97 | 100 | 41665 | 1342
[code]....
I need to extract the Info from the RC column for the first 4 players of liverpool. The test code i have does the same,but can anyone show me a better way of doing it.I could do it easily with gawk -F"|" and print the respective column,but i need to do this in perl.
Code:
#!/usr/bin/perl
use strict;
use warnings;
[code]....
View 7 Replies
View Related
May 12, 2010
I have a huge (over 10 gb) file with a list of IP's each followed by a corresponding number like this:
Code:
12.32.34.23 10
143.32.34.543 11
232.32.45.65 12
54.23.5.232 13
143.32.34.43 14
and so on..
I'm trying to sort this file numerically and weed out any duplicate IP addresses. How do I do this on bash? I have come up with this but obviously it does'nt work.
Code:
$sort -n myfile.txt | cut -f1 | uniq -u
View 2 Replies
View Related
May 14, 2010
i have a compiled data as follows:
c1
0
0
0
[Code]......
View 13 Replies
View Related
Mar 13, 2010
I need to search a string which is in the first line and print that column.
For e.g
Code:
$ top -bn1 | head -20 | awk '/PID/,/*/'
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 13737 admin 15 0 2476 936 680 R 2 0.0 0:00.01
[Code]....
View 6 Replies
View Related
Mar 17, 2009
I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').
The problem is that by the default the sort is case-sensitive so the array looks like this:
Code:
Apple 4015
Banana 4011
Cherry 4045
avocado 4046
I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like:
Code:
Apple 4015
avocado 4046
Banana 4011
Cherry 4045
How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.
View 2 Replies
View Related
Jul 2, 2010
i have a script to read a file and get each column with varibles.actually my file: hplog1 sample 3 lines consists of
client1_day- 2010
jan
client2 2009
[code]....
View 1 Replies
View Related
Jun 19, 2011
I need a better tutorial than the out of date books I own or I can find using Google. If someone has a place they would recommend, please provide a link. I have a web page that is 3 column. I would like each column to vertical scroll separately. I would also like to keep the jump code in the left column if that is possible. Go here for the my web page and source code. [URL]
View 3 Replies
View Related
Apr 24, 2010
Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.
[code]....
My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:
[code]....
Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.
[code]....
how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?
View 10 Replies
View Related
Mar 3, 2009
I like running sql queries from the command line.
Code:
sqlite3 foo.db "select * from some table"
How can I specify
Code:
.mode column
at the command line?
View 1 Replies
View Related
May 1, 2010
Trying to change to upper case first letter of every word over a specific column.
View 10 Replies
View Related
Jan 7, 2011
All I want is a command that reads one data file with several columns and prints it in another one.However, whenever the value in one specific column alters, it prints one empty line in the new file. For example, consider the file
2.54000000 2.54000000
2.54000000 2.54000000
2.54000000 2.54000000
2.54000000 2.56000000
[code]....
View 9 Replies
View Related