AWK line by line instead of field by field?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK line by line instead of field by field?
# 1  
Old 07-06-2005
AWK line by line instead of field by field?

I've been using a lot of awk lately for csv files.
But I've been using awk for csv files that contain 32 fields per line.

For the first time, I've been given a csv file that contains one field per line (13 fields in each csv file).

I need to check that a specific field, or line contains a string.
There are no commas or delimiters at the end of each line.

Here's how I would calculate it if all fields were in one line.
Code:
trade_count=`awk -F, '$7 ~ /:22A:NEWT/ { trade_count++ } END { print trade_count }' myCSV.csv`

How would I convert that to a csv file that has one field per line?

I found this in another post, how do I apply it to what I want to accomplish?
awk '{ if(NR == 7) print}' <filename>
# 2  
Old 07-06-2005
Change $7 to $0 -- $0 is the whole line
# 3  
Old 07-06-2005
Smilie Oh my goodness.

I feel so dumb I'm laughing at myself right now.
That worked so well.......

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

awk to remove line if field has symbols in it

Trying to use awk to remove a line only if $1 contains either ; or :. Thje awk below runs but no lines are removed. Thank you :). awk awk '$1 !~ /;/ || $1 !~ /:/ { print }' file file AARS2;TMEM151B 1 AASS 2 ABAT 3 ABCA1 3 ABCA10 1 ABCA12 2 ABCA13 1 ABCA13:AX746840 2 ABCA2 5 (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

4. UNIX for Dummies Questions & Answers

Help with awk, where line length and field position are variable

I have several questions about using awk. I'm hoping someone could lend me a hand. (I'm also hoping that my questions make sense.) I have a file that contains pipe separated data. Each line has similar data but the number of fields and the field position on each line is variable. ... (3 Replies)
Discussion started by: Cheese64
3 Replies

5. UNIX for Dummies Questions & Answers

Values with common field in same line with awk

Hi all ! I almost did it but got a small problem. input: cars red cars blue cars green truck black Wanted: cars red-blue-green truck black Attempt: gawk 'BEGIN{FS="\t"}{a = a (a?"-":"")$2; $2=a; print $1 FS $2}' input But I also got the intermediate records... (2 Replies)
Discussion started by: beca123456
2 Replies

6. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

7. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

8. Shell Programming and Scripting

Replace line and field using SED and/or AWK or some other suggestion

QUESTION 1: How do you replace a specific line (i.e. line 4) with a new user defined line (i.e. the contents of SAMS’s name, history, math and English grades have been set already). I have been attempting to use SED (FYI: I don’t have GNU SED) or AWK, but haven’t had any luck. FYI: I am using... (1 Reply)
Discussion started by: thibodc
1 Replies

9. UNIX for Advanced & Expert Users

awk for a line that contains someting in a field

How would I do something like this when field 4 contains "John". I only want to print field 1 and 4 when when field 4 contains"John". awk -F" " '{print $1 $4} (3 Replies)
Discussion started by: cokedude
3 Replies

10. Shell Programming and Scripting

awk append to one line if first field is the same

Hi all, How would I append the second field each time to one line if the first field is the same for example I have this data: 10430,187976 10430,251588 10430,262904 10430,275008 10430,279892 10430,275008 10430,303740 10430,318136 10430,336988 10430,350324 10430,373648 And I... (4 Replies)
Discussion started by: borderblaster
4 Replies
Login or Register to Ask a Question