Sponsored Content
Top Forums Shell Programming and Scripting How to (n)awk lines of CSV with certain number of fields? Post 302410984 by Coach- on Wednesday 7th of April 2010 09:57:28 AM
Old 04-07-2010
Please try with this

awk -F"," ' NF == 4 {print }' myfile

I think this should work.Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Re-usable function to parse csv files with different number of fields

Hi there, been pondering how to deal with this and hoping someone would give me an insight on this. I need help on creating a reusable bash funtion to parse csv files containing different number of fields (comma-seperated). My initial thought is to create function for each input csv file (20+... (2 Replies)
Discussion started by: jy2k7ca
2 Replies

2. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

3. Shell Programming and Scripting

split a csv file into specified number of files (not lines)

hi, i really need it ...it's not simple to explain but as it's part of a crontab i can't split the file manually...and the file can change every day so the lines are not a good base. example: how to split 1 csv file in 15 files? thank you very much regards :b: (4 Replies)
Discussion started by: 7stars
4 Replies

4. 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

5. Shell Programming and Scripting

Comparing two csv file fields using awk script

Hi All, I want to remove the rows from File1.csv by comparing the columns/fields in the File2.csv. I only need the records whose first column is same and the second column is different for the same record in both files.Here is an example on what I need. File1.csv: RAJAK|ACTIVE|1... (2 Replies)
Discussion started by: rajak.net
2 Replies

6. Shell Programming and Scripting

awk split lines without knowing the number of fields a-priori

I want to use awk to split fields and put them into a file but I don't know the number of fields for example, in the following line Ports: 22/filtered/tcp//ssh///, 53/open/tcp//tcpwrapped///, 111/filtered/tcp//rpcbind///, 543/filtered/tcp//klogin///, 544/filtered/tcp//kshell///,... (3 Replies)
Discussion started by: esolvepolito
3 Replies

7. Shell Programming and Scripting

[ksh88 and awk] Number of fields with a value.

Hi, With: # VALUES="one~two~~~" # echo $VALUES | awk 'BEGIN {FS="~"} {print NF}' 5 I can determine the number of fields. How to determine the number of fields with a value ? In this case 2. Thanks in advance, ejdv (6 Replies)
Discussion started by: ejdv
6 Replies

8. Shell Programming and Scripting

Awk: Combine multiple lines based on number of fields

If a file has following kind of data, comma delimited 1,2,3,4 1 1 1,2,3,4 1,2 2 2,3,4 My required output must have only 4 columns with comma delimited 1,2,3,4 111,2,3,4 1,222,3,4 I have tried many awk command using ORS="" but couldnt progress (10 Replies)
Discussion started by: mdkm
10 Replies

9. UNIX for Beginners Questions & Answers

How to count lines of CSV file where 2 fields match variables?

I'm trying to use awk to count the occurrences of two matching fields of a CSV file. For instance, for data that looks like this... Joe,Blue,Yes,No,High Mike,Blue,Yes,Yes,Low Joe,Red,No,No,Low Joe,Red,Yes,Yes,Low I've been trying to use code like this... countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies

10. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies
NF2CSV(1)						      General Commands Manual							 NF2CSV(1)

NAME
nf2csv - iptables to CSV data SYNOPSIS
nf2csv [options] DESCRIPTION
nf2csv Parses iptables log messages and generates comma-separate value formatted data. This is useful to provide input to the AfterGlow project (see http://afterglow.sourceforge.net) so iptables logs can be visualized graphically. An interesting application of nf2csv and AfterGlow is to parse and visualize the iptables logfiles made available by the Honeynet project in their Scan of the Month challenges. The Scan30 and Scan34 challenges (see http://www.honeynet.org/scans/scan30/ and http://www.honeynet.org/scans/scan34/) contain extensive iptables logfiles, and some graphical representations of these can be viewed here: http://www.cipherdyne.org/psad/honeynet/. The psad pro- gram also has the ability to generate CSV data from iptables logs with its --CSV mode. OPTIONS
-f, --fields <tokens> Specify the set of fields that should be printed from iptables log messages. The most common usage of this argument is SRC DST DPT to print the source and destination IP addresses, followed by the destination port number. Available fields to print include: SRC, SPT, DST, DPT, PROTO, LEN, IN, TOS, TTL, SEQ, ID, TYPE, CODE (and these can also be referred to as src, dst, sp, dp, proto, ip_len, intf, tos, and ttl). There are several additional fields that are not given specific tags within iptables log messages, and these can be included by specifying one of the following: flags, top_opts, ip_opts, chain, log_prefix, frag_bit, src_mac, dst_mac, and udp_len. Each of these fields accepts a search criteria in the form of a numeric comparison, string match, or IP match. See the EXAMPLES section below for more information. -u, --unique-lines Only print unique output lines. This can drastically reduce the output of nf2csv depending on the characteristics of the iptables logfile that is being parsed. -m, --max-lines <num> Specify the maximum number of output lines nf2csv will generate. This is useful for providing a limited set of data to AfterGlow in order to make visualizations more clear and less cluttered. -r, --regex <regex> Specify a regular expression that must match against the entire iptables log message in order for it to be included within the CSV output. This allows log messages to be included from the output with all of the flexibility of regular expressions. See the EXAM- PLES section below for more information. -n, --neg-regex <regex> Specify a regular expression that must not match against the iptables log message in order for it to be included within the CSV out- put. This allows log messages to be excluded from the output with all of the flexibility of regular expressions. See the EXAMPLES section below for more information. -s, --start-line <line> Specify the starting line where nf2csv begins to process iptables log data. If you are processing a huge file with thousands of iptables log messages this option can be useful to parse a specific chunk of this data. Also see the --end-line option below. -e, --end-line <line> Specify the last line of iptables log data that nf2csv will parse. EXAMPLES
The following examples illustrate the command line arguments that could be supplied to nf2csv in a few situations: Print source and destination IP addresses and the destination port number: $ nfcsv -f src dst dp Same as above, but now require that the source IP come from the 11.11.11.0/24 subnet: $ nfcsv -f src:11.11.11.0/24 dst dp Display instances of the MyDoom worm: $ nfcsv -f src dst dp:3127 Display packets that have low TTL values: $ nfcsv -f src dst ttl:<10 Display all traffic to or from the host 11.11.11.67 (this sets up an OR condition between the src and dst fields): $ nfcsv -f src dst dp -r 11.11.11.67 Display likely instances of Window Messanger popup spam attempts (note the use of the --regex argument to require minimal lengths on the UDP length field and source port, but the output contains the destination port of 1026): $ nfcsv -f src dst dp -r SPT={4}.*LEN=[4-9]{2} SEE ALSO
psad(8) AUTHOR
Michael Rash <mbr@cipherdyne.org> BUGS
Send bug reports to mbr@cipherdyne.org. Suggestions and/or comments are always welcome as well. DISTRIBUTION
nf2csv is distributed with the psad project (http://www.cipherdyne.org/psad/) under the GNU General Public License (GPL), and the latest version may be downloaded from http://www.cipherdyne.org/ Linux Jun, 2006 NF2CSV(1)
All times are GMT -4. The time now is 05:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy