Sponsored Content
Top Forums Shell Programming and Scripting Find Data in test file and write each out to a line Post 302958728 by kcpoole on Monday 26th of October 2015 01:20:13 AM
Old 10-26-2015
Find Data in test file and write each out to a line

I have a .csv file that has been create from a google form and I need to extract the data from it that has been entered by users.
The CSV will have anywhere between 100 and 1000 lines which comprise entr data for a sports carnival

A few typical line is shown here to show the problem I have
Code:
 26/10/2015 11:58:26,KL,,22,name1,name2,F,9,,,,,,,,,70,100,200,400,,,,, 
26/10/2015 12:01:28,KL,,22,name3,name4,F,8,70,100,200,700s,,,,,,,,,,,,,
26/10/2015 12:01:28,KL,,22,name5,name6,F,8,,,,,,,,,,,,,,HJ,LJ,DT,SP,

From this data, I need to extract the data in the last part of the lines,
This data can be Alpha or numeric or combination of and between 2-4 chanractes in length. It could be in any position within the last blank fields.
there could be anywhere between 1 and 6 entries on each line that ineed to capture.

For each entry, I need to write out a single formatted line which I already have most of in the form
Code:
D;Name2;name1;;F;;KIN;KL;9;;70;;M;1;22;;;;
D;Name2;name1;;F;;KIN;KL;9;;100;;M;1;22;;;;
D;Name2;name1;;F;;KIN;KL;9;;200;;M;1;22;;;;
D;Name2;name1;;F;;KIN;KL;9;;400;;M;1;22;;;;

How do I capture to a variable, The Last data on each line from random positions and then proceed to the next line when done?

I am stumped!

Thanks in advance
Ken

---------- Post updated at 04:20 PM ---------- Previous update was at 03:51 PM ----------

I had thought of using cut to query the first Column to test ( cut -d , -f9 ), if it has a non zero value, then must have data so write line, and then increment column and test again.
If value = LF? then proceed to next line

is there a better way that interativley testing each column?

Ken
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

2. Hardware

how to write data into a device file?

Hi, I am working in device drivers. I am new to device drivers. i have invoked chardev.c. the driver is insmoded. now i want to write something into this and i want to look what i have written. but i don't know how to write and see. please help me (0 Replies)
Discussion started by: boidi
0 Replies

3. Shell Programming and Scripting

Find line number of bad data in large file

Hi Forum. I was trying to search the following scenario on the forum but was not able to. Let's say that I have a very large file that has some bad data in it (for ex: 0.0015 in the 12th column) and I would like to find the line number and remove that particular line. What's the easiest... (3 Replies)
Discussion started by: pchang
3 Replies

4. Programming

How to write data to file in C?

Hi I want to open a file and write data in the following manner. Header String 1 String 2 String 3 String 4 String 5 ... (4 Replies)
Discussion started by: AAKhan
4 Replies

5. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

6. Shell Programming and Scripting

Find common entries in 2 list and write data before it

Hi all, I have 2 files: second file I want if entries in one file will match in other file. It shuld wite approve before it so output shuld be (1 Reply)
Discussion started by: manigrover
1 Replies

7. Shell Programming and Scripting

Find matches and write the data before it

Hi all I am here for help once again I have two files One file is like this with one columns F2 B2 CAD KGM HTC CSP Second file is like this in 5 columns where firs column contain sometime entries of first file with space and other entries (12 Replies)
Discussion started by: Priyanka Chopra
12 Replies

8. Shell Programming and Scripting

Write over data to new file

hi..i would ask about how to write over data to new file with BASH. so..assume my data looks like this : 11 12 13 14 15 ...and so on. It's always line by line. and that's for the first file. i want to write over those numbers into second file but by using space. so my second file should be... (5 Replies)
Discussion started by: syalala
5 Replies

9. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

10. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies
LINK(2) 						      BSD System Calls Manual							   LINK(2)

NAME
link -- make a hard file link LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> int link(const char *name1, const char *name2); int linkat(int fd1, const char *name1, int fd2, const char *name2, int flags); DESCRIPTION
The link() function call atomically creates the specified directory entry (hard link) name2 with the attributes of the underlying object pointed at by name1. If the link is successful: the link count of the underlying object is incremented; name1 and name2 share equal access and rights to the underlying object. If name1 is removed, the file name2 is not deleted and the link count of the underlying object is decremented. name1 must exist for the hard link to succeed and both name1 and name2 must be in the same file system. name1 may not be a directory unless the caller is the super-user and the file system containing it supports linking to directories. When operating on a symlink, link() resolves the symlink and creates a hard link on the target. linkat() will do the same if AT_SYMLINK_FOLLOW is set in flags, but it will link on the symlink itself if the flag is clear. At the moment, linkat() is partially implemented. It will return ENOSYS for fd1 and fd2 values different than AT_FDCWD. RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
link() will fail and no link will be created if: [EACCES] A component of either path prefix denies search permission, or the requested link requires writing in a directory with a mode that denies write permission. [EDQUOT] The directory in which the entry for the new link is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. [EEXIST] The link named by name2 does exist. [EFAULT] One of the pathnames specified is outside the process's allocated address space. [EIO] An I/O error occurred while reading from or writing to the file system to make the directory entry. [ELOOP] Too many symbolic links were encountered in translating one of the pathnames. [EMLINK] The link count of the file named by name1 would exceed {LINK_MAX}. [ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] A component of either path prefix does not exist, or the file named by name1 does not exist. [ENOSPC] The directory in which the entry for the new link is being placed cannot be extended because there is no space left on the file system containing the directory. [ENOTDIR] A component of either path prefix is not a directory. [EOPNOTSUPP] The file system containing the file named by name1 does not support links. [EPERM] The file named by name1 is a directory and the effective user ID is not super-user, or the file system containing the file does not permit the use of link() on a directory. [EROFS] The requested link requires writing in a directory on a read-only file system. [EXDEV] The link named by name2 and the file named by name1 are on different file systems. SEE ALSO
symlink(2), unlink(2) STANDARDS
The link() function conforms to ISO/IEC 9945-1:1990 (``POSIX.1''). BUGS
linkat() is partially implemented. BSD
January 12, 1994 BSD
All times are GMT -4. The time now is 05:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy