my favorit is from comp.lang.awk - that's if you don't have 'gawk'. If you do have 'gawk' installed, it already has the 'FIELDWIDTHS' capability built in.
You enhance that by passing the 'FIELDWIDTHS' on cli:
Code:
function setFieldsByWidth( i,n,FWS,start,copyd0) {
# Licensed under GPL Peter S Tillier, 2003
# NB corrupts $0
copyd0 = $0 # make copy of $0 to work on
if (length(FIELDWIDTHS) == 0) {
print "You need to set the width of the fields that you require" > "/dev/stderr"
print "in the variable FIELDWIDTHS (NB: Upper case!)" > "/dev/stderr"
exit(1)
}
if (!match(FIELDWIDTHS,/^[0-9 ]+$/)) {
print "The variable FIELDWIDTHS must contain digits, separated" > "/dev/stderr"
print "by spaces." > "/dev/stderr"
exit(1)
}
n = split(FIELDWIDTHS,FWS)
if (n == 1) {
print "Warning: FIELDWIDTHS contains only one field width." > "/dev/stderr"
print "Attempting to continue." > "/dev/stderr"
}
start = 1
for (i=1; i <= n; i++) {
$i = substr(copyd0,start,FWS[i])
start = start + FWS[i]
}
}
#Note that the "/dev/stderr" entries in some lines have wrapped.
#I then call setFieldsByWidth() in my main awk code as follows:
BEGIN {
#FIELDWIDTHS="7 6 5 4 3 2 1" # for example
FIELDWIDTHS="1 3 8 8 5 9 1 9" # for example
OFS="|"
}
!/^[ ]*$/ {
saveDollarZero = $0 # if you want it later
setFieldsByWidth()
# now we can manipulate $0, NF and $1 .. $NF as we wish
print $0 OFS
next
}
Hi
Guys
I have downloaded a table from oracle database in .csv format. it has many fields as Title, First Name, Last Name etc. I have to download distinct titles from database and now i have to check all those titles from data of First Name one by one. and then i have to delete matched record.... (1 Reply)
HI ,
I am new to shell scripting ,
I have a requirement that
I send a file for data quality ( original.csv) & i will be getting 4 files daily into a particular directory in return with cleansed data .
the files may be clean.csv,
unclean.csv ,
... (2 Replies)
-Hi, I have a problem with parcing/spliting a file record into two parts and assigning the split parts to two viriables. The record is as follows:
ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb ... (5 Replies)
Hello Gurus,
We have a requirement to count the valid number of records in a comma delimited file with double quotes.
The catch here is..few records have a new line carriage within the double quotes,,say for ex:we have a file called accounts the record count is 4827..but the actual valid count... (5 Replies)
Hi,
I have a script which creates and modifies a csv file.
I have managed to do everything I need to do apart from 1 thing. I need to append a trailer record to the file. I need this line to hold the total of an entire column of the csv file (skipping the 1st line which is a header).
Can... (2 Replies)
Hello All,
I have a large file, more than 50,000 lines, and I want to split it in even 5000 records. Which I can do using
sed '1d;$d;' <filename> | awk 'NR%5000==1{x="F"++i;}{print > x}'Now I need to add one more condition that is not to break the file at 5000th record if the 5000th record... (20 Replies)
Hi,
I have to output a new csv file from an input csv file with first unique value in the first column.
input csv file
color product id status
green 102 pass
yellow 201 hold
yellow 202 keep
green 101 ok
green 103 hold
yellow 203 ... (5 Replies)
riends
I have the following problem:
test.txt I have a file that has the following contents:
is a fixed-length file to the end of the number 12 has spaces, so that it is fixed length
123456789
123456789
123456789
12
This code shows me the length of each record, but in... (2 Replies)
I was wondering if anyone could explain to me how to split a variable length EBCDIC file into seperate files based on the record key. I have the COBOL layout, and so I need to split the file into 13 different EBCDIC files so that I can run each one through a C++ converter I have, and get the... (11 Replies)
Hi,
I have received a file which is 20 GB. We would like to split the file into 4 equal parts and process it to avoid memory issues.
If the record delimiter is unix new line, I could use split command either with option l or b.
The problem is that the line terminator is |##|
How to use... (5 Replies)
Discussion started by: Ravi.K
5 Replies
LEARN ABOUT DEBIAN
explain_ustat_or_die
explain_ustat_or_die(3) Library Functions Manual explain_ustat_or_die(3)NAME
explain_ustat_or_die - get file system statistics and report errors
SYNOPSIS
#include <libexplain/ustat.h>
void explain_ustat_or_die(dev_t dev, struct ustat *ubuf);
int explain_ustat_on_error(dev_t dev, struct ustat *ubuf);
DESCRIPTION
The explain_ustat_or_die function is used to call the ustat(2) system call. On failure an explanation will be printed to stderr, obtained
from the explain_ustat(3) function, and then the process terminates by calling exit(EXIT_FAILURE).
The explain_ustat_on_error function is used to call the ustat(2) system call. On failure an explanation will be printed to stderr, obtained
from the explain_ustat(3) function, but still returns to the caller.
dev The dev, exactly as to be passed to the ustat(2) system call.
ubuf The ubuf, exactly as to be passed to the ustat(2) system call.
RETURN VALUE
The explain_ustat_or_die function only returns on success, see ustat(2) for more information. On failure, prints an explanation and exits,
it does not return.
The explain_ustat_on_error function always returns the value return by the wrapped ustat(2) system call.
EXAMPLE
The explain_ustat_or_die function is intended to be used in a fashion similar to the following example:
explain_ustat_or_die(dev, ubuf);
SEE ALSO ustat(2)
get file system statistics
explain_ustat(3)
explain ustat(2) errors
exit(2) terminate the calling process
COPYRIGHT
libexplain version 0.52
Copyright (C) 2009 Peter Miller
explain_ustat_or_die(3)