awk with tsv & csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk with tsv & csv
# 1  
Old 09-09-2010
awk with tsv & csv

Hi! HELP! I have a few issues...

I have a tsv with headers time, binary time, bytes, and bits. I'm trying to extract only time & bits. (Trying to graph throughput)

Using:
Code:
awk -F"\t" '{print $1, "\t"$4}' infile.tsv > outfile.tsv

Output is only the headers: time bits

Thinking it may just be syntax, I imported the tsv into excel and saved as a csv.

Used:
Code:
awk -F, '{print $1, ","$4}' infile.csv > outfile.csv

Output is time (\t),bits.

Also I'm trying to extract a range of time with the column format M/dd/yy hh:MM AM =>I have nooo idea how to do that.

I tried
Code:
grep "8/12/10" in.tsv > out.tsv

TIA!

Last edited by Franklin52; 09-10-2010 at 04:30 AM.. Reason: Please use code tags!
# 2  
Old 09-09-2010
Quote:
Originally Posted by calitiggr
...
I have a tsv with headers time, binary time, bytes, and bits. I'm trying to extract only time & bits. (Trying to graph throughput)

Using:
awk -F"\t" '{print $1, "\t"$4}' infile.tsv > outfile.tsv

Output is only the headers: time bits

Thinking it may just be syntax, I imported the tsv into excel and saved as a csv.

Used:
awk -F, '{print $1, ","$4}' infile.csv > outfile.csv

Output is time (\t),bits.
...

Unless you show us your input file, the output that your scripts spew, and what's disagreeable in the output, it's difficult to guess your problem from your post.

Code:
$ 
$ 
$ cat f5.csv
t1,bt1,byte1,bit1
t2,bt2,byte2,bit2
t3,bt3,byte3,bit3
$ 
$ awk -F, '{print $1, ","$4}' f5.csv
t1 ,bit1
t2 ,bit2
t3 ,bit3
$ 
$ # result as expected
$

awk isn't broken, the last time I checked.

tyler_durden
# 3  
Old 09-10-2010
Sorry! I'm a newbie.

Using script:
Code:
awk -F, '{print $1, ","$4}' in_bits.csv > out.csv

Sample input:
Code:
time,binary time,bytes,bits,accum,num packets,resolution 1.0
8/12/10 20:49,1281646165,24006,192048,24006,102,
8/12/10 20:49,1281646166,1752,14016,25758,22,
8/12/10 20:49,1281646167,494,3952,26252,8,

output after running script:
Code:
time ,bits

what I wanted:
Code:
time, bits
8/12/10 20:49,192048
8/12/10 20:49,14016
8/12/10 20:49,3952

Script:
Code:
awk -F"\t" '{print $1, "\t"$4, "\t"$4*8}' infile.tsv > out.tsv

Here's a sample input file.
Code:
time	binary time	bytes	accum	num packets	resolution 1.0
8/12/10 8:49 PM	1281646165	24006	24006	102	
8/12/10 8:49 PM	1281646166	1752	25758	22	
8/12/10 8:49 PM	1281646167	494	26252	8	
8/12/10 8:49 PM	1281646168	60	26312	1

script output:
Code:
time 	accum

what I wanted:
Code:
time   bytes     bytes
8/12/10 8:49 PM	124006  992048
8/12/10 8:49 PM	1752     14016
8/12/10 8:49 PM	494       3952
8/12/10 8:49 PM	60         480

then i wanted to take all values matching 8/12/10 and copy to another csv/tsv file

Hopefully this clarifies my problem Smilie



Moderator's Comments:
Mod Comment Please use code tags, thank you!

Last edited by Franklin52; 09-10-2010 at 04:35 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

2. Shell Programming and Scripting

Split each column in TSV file to be new line?

My TSV looks like: Hello my name is John \t Hello world \t Have a good day! \t See you later! Is there a simple bash script that splits the tsv on tab to: Hello my name is John Hello world Have a good day! See you later! I'm really stuck, would appreciate any help! (5 Replies)
Discussion started by: pxalpine
5 Replies

3. Shell Programming and Scripting

Replacing FQDN by hostnames in a CSV file with sed & awk

Hello, Beginning with shell scipting, I'm trying to find in a csv file, the lines where the field related to hostname is displayed as an FQDN intead the hostname. (some lines are correct) and the to correct that inside the file: Novell,11.0,UNIX Server,bscpsiws02,TxffnX1tX1HiDoyBerrzWA==... (2 Replies)
Discussion started by: Wonto
2 Replies

4. UNIX for Dummies Questions & Answers

Help with changing header of tsv with 30 million lines

Hi My 30 million line file has a header chr start end strand ref_context repeat_masked s1_smpl_context s1_c_count s1_ct_count s1_non_ct_count s1_m% s1_score s1_snp s1_indels s2_smpl_context s2_c_count s2_ct_count s2_non_ct_count s2_m% s2_score s2_snp s2_indels ... (2 Replies)
Discussion started by: plumb_r
2 Replies

5. Shell Programming and Scripting

awk read column csv and search in other csv

hi, someone to know how can i read a specific column of csv file and search the value in other csv columns if exist the value in the second csv copy entire row with all field in a new csv file. i suppose that its possible using awk but i m not expertise thanks in advance (8 Replies)
Discussion started by: giankan
8 Replies

6. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

7. Shell Programming and Scripting

pattern grep using Perl in .TSV file

Hi All, I have a .TSV extension file having ~1 Gig data and I need to grep a pattern in that file using perl. I am not able to read the file using perl any suggestions on this/ If I Change the format my data gets mismangled so I am bothered about using specific format as well. #!... (3 Replies)
Discussion started by: vmsenthil
3 Replies

8. UNIX for Dummies Questions & Answers

tsv file comparison

Hi Guys, I have to write a script to compare the tsv files headers with the values stored in the variable in bash. I have declared variables as HEADER_VERSION="All Versions\tVersion Type\tVersion\tLevel" now file contains data as follows: All Versions Version Type Version Level... (0 Replies)
Discussion started by: Swapna173
0 Replies

9. Shell Programming and Scripting

creating & sending formatted (with bolds & colors) CSV

Hi , I have a situation. Need is to create & send a formatted file with header in BOLD & colored & some sequel results as a content. I know echo -e \033 command, but its scope is limited in PUTTY. How to retain the formatting out of Putty; say after someone opens a email attachment... (2 Replies)
Discussion started by: infaWorld
2 Replies

10. UNIX for Dummies Questions & Answers

Converting csv to tsv and back

Anyone have a simple UNIX script to look at for doing this? I'm interested in how to convert from csv to tsv, and then back again, if I want to. Thanks! (13 Replies)
Discussion started by: doubleminus
13 Replies
Login or Register to Ask a Question