Sponsored Content
Full Discussion: Parsing a CSV File
Top Forums Shell Programming and Scripting Parsing a CSV File Post 302389656 by frans on Monday 25th of January 2010 12:36:11 PM
Old 01-25-2010
post a sample of your file (CSV can be comma, semicolon or tab separated and values maybe quoted).
The basics :
Code:
#!/bin/bash
IFS=',' # if it is comma separated
while read HOST DATE STATUS
do
    [ "$STATUS" = "Expired" ] && continue
    # Process Host
    echo "Host: $HOST"
    # Process Date
    echo "Date: $DATE"
    # Process Status
    echo "Staus: $STATUS"
done < file.csv # The name of the file to be processed

For host, date and status processing i justa put an 'echo to see the variable value.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in parsing a CSV file with Shell script

I have a CSV file which contains number series as one of the fields. Some of the records of the field look like : 079661/3 I have to convert the above series as 079661 079662 079663 and store it as 3 different records. Looking for help on how to achieve this. Am a newbie at Shell... (10 Replies)
Discussion started by: mihirk
10 Replies

2. Shell Programming and Scripting

Parsing a csv file

I am trying to parse a csv file in the below 'name-value pair' format and then use the values corresponding to the name. Type:G,Instance:instance1,FunctionalID:funcid,Env:dev,AppName:appname... (6 Replies)
Discussion started by: chiru_h
6 Replies

3. Shell Programming and Scripting

CSV file parsing and validation

I have a CSV file that needs to through two seperate processes (in the end there will be 2 files (Dload.unl and Tload.unl and we'll say the input file name is mass.csv). I have a processfile() function that will call the process Dload funtion. In Dload I want to read mass.csv into Dload and then... (1 Reply)
Discussion started by: dolo21taf
1 Replies

4. Shell Programming and Scripting

2 problems: Mailing CSV file / parsing CSV for display

I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out! I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a... (6 Replies)
Discussion started by: soldstatic
6 Replies

5. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

6. Shell Programming and Scripting

Parsing a CSV file and deleting all rows on condition

Hello list, I am working on a csv file which contains two fields per record which contain IP addresses. What I am trying to do is find records which have identical fields(IP addresses) which occur 4(four) times, and if they do, delete all records with that specific identical field(ip address). ... (4 Replies)
Discussion started by: landossa
4 Replies

7. Shell Programming and Scripting

Help required in parsing a csv file

Hi Members, I am stuck with the following problem. Request your kind help I have an csv file which contains, 1 header record, data records and 1 footer record. Sample is as below Contents of cm_update_file_101010.csv -------------------------------------------------- ... (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

8. Shell Programming and Scripting

Parsing csv file and pass to a variable

Hi, Newbie here and I need some help to parse a csv file that contains fields separated by ",". What I need to achieve here is, read the 1 line file and extract 240 fields and pass to a variable and then read the next 240 fields and pass to a variable, over and over. If anyone can assist that... (4 Replies)
Discussion started by: tmslixx
4 Replies

9. Shell Programming and Scripting

Csv file parsing and validating

Hi, I have basic knowledge on unix shell scripting(not an expert). My requirement is reading the csv file using the schema defined in the configuration file and if the condition is not mached then move the unmatched record to a error file and matched good records into other file. In brief: ... (43 Replies)
Discussion started by: shree11
43 Replies

10. Shell Programming and Scripting

Help with Parsing a CSV File

Hello All, I have an input CSV file like below, where first row data can be in different position after every run of the tool, i.e. pzTest in below example is in column 1, but it can be also in 3 column and same for all the headers in the first row. pzTest, pzExtract, pxUpdate, pzInfo... (1 Reply)
Discussion started by: asirohi
1 Replies
SOCKET_RECV(3)								 1							    SOCKET_RECV(3)

socket_recv - Receives data from a connected socket

SYNOPSIS
int socket_recv (resource $socket, string &$buf, int $len, int $flags) DESCRIPTION
The socket_recv(3) function receives $len bytes of data in $buf from $socket. socket_recv(3) can be used to gather data from connected sockets. Additionally, one or more flags can be specified to modify the behaviour of the function. $buf is passed by reference, so it must be specified as a variable in the argument list. Data read from $socket by socket_recv(3) will be returned in $buf. PARAMETERS
o $socket - The $socket must be a socket resource previously created by socket_create(). o $buf - The data received will be fetched to the variable specified with $buf. If an error occurs, if the connection is reset, or if no data is available, $buf will be set to NULL. o $len - Up to $len bytes will be fetched from remote host. o $flags - The value of $flags can be any combination of the following flags, joined with the binary OR ( |) operator. Possible values for $flags +-------------+---------------------------------------------------+ | Flag | | | | | | | Description | | | | +-------------+---------------------------------------------------+ | | | | MSG_OOB | | | | | | | Process out-of-band data. | | | | | | | | MSG_PEEK | | | | | | | Receive data from the beginning of the receive | | | queue without removing it from the queue. | | | | | | | |MSG_WAITALL | | | | | | | Block until at least $len are received. However, | | | if a signal is caught or the remote host discon- | | | nects, the function may return less data. | | | | | | | |MSG_DONTWAIT | | | | | | | With this flag set, the function returns even if | | | it would normally have blocked. | | | | +-------------+---------------------------------------------------+ RETURN VALUES
socket_recv(3) returns the number of bytes received, or FALSE if there was an error. The actual error code can be retrieved by calling socket_last_error(3). This error code may be passed to socket_strerror(3) to get a textual explanation of the error. EXAMPLES
Example #1 socket_recv(3) example This example is a simple rewrite of the first example from "Examples" to use socket_recv(3). <?php error_reporting(E_ALL); echo "<h2>TCP/IP Connection</h2> "; /* Get the port for the WWW service. */ $service_port = getservbyname('www', 'tcp'); /* Get the IP address for the target host. */ $address = gethostbyname('www.example.com'); /* Create a TCP/IP socket. */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . " "; } else { echo "OK. "; } echo "Attempting to connect to '$address' on port '$service_port'..."; $result = socket_connect($socket, $address, $service_port); if ($result === false) { echo "socket_connect() failed. Reason: ($result) " . socket_strerror(socket_last_error($socket)) . " "; } else { echo "OK. "; } $in = "HEAD / HTTP/1.1 "; $in .= "Host: www.example.com "; $in .= "Connection: Close "; $out = ''; echo "Sending HTTP HEAD request..."; socket_write($socket, $in, strlen($in)); echo "OK. "; echo "Reading response: "; $buf = 'This is my buffer.'; if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) { echo "Read $bytes bytes from socket_recv(). Closing socket..."; } else { echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . " "; } socket_close($socket); echo $buf . " "; echo "OK. "; ?> The above example will produce something like: <h2>TCP/IP Connection</h2> OK. Attempting to connect to '208.77.188.166' on port '80'...OK. Sending HTTP HEAD request...OK. Reading response: Read 123 bytes from socket_recv(). Closing socket...HTTP/1.1 200 OK Date: Mon, 14 Sep 2009 08:56:36 GMT Server: Apache/2.2.3 (Red Hat) Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT ETag: "b80f4-1b6-80bfd280" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8 OK. PHP Documentation Group SOCKET_RECV(3)
All times are GMT -4. The time now is 11:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy