Sponsored Content
Top Forums Shell Programming and Scripting Consolidate several lines of a CSV file with firewall rules, in order to parse them easier? Post 302862701 by starriol on Friday 11th of October 2013 09:24:58 AM
Old 10-11-2013
Quote:
Originally Posted by Chubler_XL
Try this awk solution:

Code:
awk -F\; '
$1{Save=$0}
/^;/{
  for(i=split(Save,Prev,";");i;i--)
    if (!length($i)) $i=Prev[i]
}1' OFS=\; infile

Hey Cluber, thanks for this code.
My knowledge of awk is null, basically.
I ran it and got to this:
Code:
pgawk: script.awk:1: awk -F\; '
pgawk: script.awk:1:       ^ backslash not last character on line

I'm running this with Gawk for Windows (not at my laptop here).
Is that the reason why I'm getting this error?
If it is, I'll get a Linux VM running to test it out.

Thanks.
Moderator's Comments:
Mod Comment Use CODE tags for sample input and sample output; not just for code segments. Without the CODE tags, the spacing in the diagnostic messages from awk is lost.

Last edited by Don Cragun; 10-13-2013 at 12:08 AM.. Reason: Add CODE tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to Parse a CSV file into a Different Format

Hi I have a CSV file with me in this format Currency, USD, EUR, USD, 1.00, 1.32, EUR, 0.66, 1.00, How do I transpose the file to get to the format below. currency, currency, rate USD, USD, 1.00 USD, EUR, 1.32 EUR, USD, 0.66 EUR, EUR, 1.00 Thanks for your help We are using... (2 Replies)
Discussion started by: cdesiks
2 Replies

2. Shell Programming and Scripting

CSV File parse help in Perl

Folks, I have a bit of an issue trying to obtain some data from a csv file using PERL. I can sort the file and remove any duplicates leaving only 4 or 5 rows containing data. My problem is that the data contained in the original file contains a lot more columns and when I try ro run this script... (13 Replies)
Discussion started by: lodey
13 Replies

3. Shell Programming and Scripting

Extra/parse lines from a file between unque lines through the file

I need help to parse a file where there are many records, all of which are consistently separated by lines containing “^=============” and "^ End of Report". Example: ============= 1 2 3 4 End of record ============= 1 3 4 End of record Etc.... I only need specific lines... (5 Replies)
Discussion started by: jouuu
5 Replies

4. Shell Programming and Scripting

parse csv file, sha1 hash and output

I have a file, not really a csv, but containing delineated data just the same. Lets call that file "raw_data.txt". It contains data in the format of company name:fein number like this: first company name:123456789 second company name:987654321 what i need to do is read this file, apply... (11 Replies)
Discussion started by: FreddyG
11 Replies

5. Shell Programming and Scripting

Parse XML file into CSV with shell?

Hi, It's been a few years since college when I did stuff like this all the time. Can someone help me figure out how to best tackle this problem? I need to parse a file full of entries that look like this: <eq action="A" sectyType="0" symbol="PGR" exch="CA" curr="VEF" sess="NORM"... (7 Replies)
Discussion started by: Pcushing
7 Replies

6. Shell Programming and Scripting

Parse csv file

Hi, Our requirement is to parse the input file(.csv format). The each column in the file is delimited with comma. We need to take each column and apply some business validation rule. If data itself contains comma, then those fields are enclosed with double quotes ("). We can see this double... (7 Replies)
Discussion started by: vfrg
7 Replies

7. Shell Programming and Scripting

how to parse this file and obtain a .csv or .xls

Hello Expert, I have a file in the following format: SYNTAX_VERSION 5 MONITOR "NAME_TEMPLATES" DESCRIPTION "Monitors for contents of error " INTERVAL "1m" MONPROG "script.sh NAME_TEMPLATES" MAXTHRESHOLD GEN_BELOW_RESET SEVERITY Major ... (17 Replies)
Discussion started by: Ant-one
17 Replies

8. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

9. Shell Programming and Scripting

Multiple lines consolidate

This post is start for me ... I stumped at something that I not sure as to how start on ... I tried so of your script that i honestly lost mind looking and looking here ... please help COL1 COl2 COL3 12222 AUH FLUEH 12222 SSC OPERA 12222 SSC ... (8 Replies)
Discussion started by: Sebastian.Thoma
8 Replies

10. Shell Programming and Scripting

How to parse this file using awk and output in CSV format?

My source file looks like this: Cust-Number = "101" Cust-Name="Joe" Cust-Town="London" Cust-hobby="tennis" Cust-purchase="200" Cust-Number = "102" Cust-Name="Mary" Cust-Town="Newyork" Cust-hobby="reading" Cust-purchase="125" Now I want to parse this file (leaving out hobby) and... (10 Replies)
Discussion started by: Balav
10 Replies
MASON(1)																  MASON(1)

NAME
mason - interactively create a firewall SYNOPSIS
mason < logfile > rulefile DESCRIPTION
This manual page briefly documents the mason command. mason interactively generates a set of firewall rules for a Linux-based firewall. This is done by turning on full IP logging, watching the logs for connections, and generating rules describing the connections seen. mason is familiar with most of the quirks of various connec- tion types (such as ftp and IRC), and can output rules for 2.0.x ipfwadm, 2.2.x ipchains, and Cisco packet filters. mason operates by reading in log file information from standard input and writing firewall rules to standard output. This allows mason to work offline or on a separate system. Real-time firewall generation can be achieved with a command like tail(1). Most users will want to run mason with a user-friendly interface such as mason-gui-text(1). ENVIRONMENT
mason is configured using the following environment variables. ECHOCOMMAND Sets the type of firewall rules that mason should output to standard out. Allowed values include "ipfwadm" and "ipchains". By default, mason outputs whatever kind of rules are supported by the currently running Linux kernel. DOCOMMAND Sets the type of firewall rules that mason should run immediately when a rule is generated. Allowed values include "ipfwadm" and "ipchains". By default, mason outputs whatever kind of rules are supported by the currently running Linux kernel. HEARTBEAT If set to "yes", mason will output a "+" or "-" to standard error whenever a rule generated by mason has been triggered. DYNIP Set this to the list of interfaces that have dynamically assigned addresses, separated by spaces. SEE ALSO
mason-gui-text(1) AUTHOR
This manual page was written by Jeff Licquia <jeff@luci.org>, for the Debian GNU/Linux system (but may be used by others). MASON(1)
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy