Find Data in test file and write each out to a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find Data in test file and write each out to a line
# 15  
Old 10-26-2015
Hi Ken,
Please show us the output from:
Code:
od -c file

for the part of the file has the line ending with:
Code:
200,400...

that is leading to the three lines of output you showed us in post #14. We need to see what is between the "400" and the <newline> character at the end of that line.
# 16  
Old 10-26-2015
This is for a 2 line input file that shows the error for the first line only
I assume because there are no blanks in the line directly before the return?

Code:
ken@Leia:~/Documents/Athletics/convertscript-Googleforms-MMv4$ od -c 3aZoneentry.csv
0000000   2   6   /   1   0   /   2   0   1   5       1   1   :   5   8
0000020   :   2   6   ,   C   l   u   b   n   a   m   e   ,   ,   2   2
0000040   ,   F   i   r   s   t   N   a   m   e   1   ,   S   e   c   o
0000060   n   d   N   a   m   e   1   ,   F   ,   9   ,   ,   ,   ,   ,
0000100   ,   ,   ,   ,   ,   7   0   ,   1   0   0   ,   2   0   0   ,
0000120   4   0   0  \r  \n   2   6   /   1   0   /   2   0   1   5    
0000140   1   1   :   5   8   :   2   6   ,   C   l   u   b   n   a   m
0000160   e   ,   ,   2   4   ,   F   i   r   s   t   N   a   m   e   3
0000200   ,   S   e   c   o   n   d   N   a   m   e   3   ,   F   ,   1
0000220   1   ,   ,   ,   ,   ,   ,   ,   ,   ,   ,   7   0   ,   1   0
0000240   0   ,   7   0   0   s   ,   D   T   ,   S   P   ,   J   T   ,
0000260   ,   ,   ,   ,   ,  \r  \n
0000267

# 17  
Old 10-26-2015
OK. We need to get rid of the <carriage-return> at the ends of the lines in your input file... So, change:
Code:
	for event in $REST
	do	[ ! "$event" ] && continue

to:
Code:
	REST="${REST%[[:space:]]}"
	for event in $REST
	do	[ ! "${event%[[:space:]]}" ] && continue

I'm guessing that just:
Code:
	REST="${REST%[[:space:]]}"
	for event in $REST
	do	[ ! "$event" ] && continue

will be enough, but if there is a trailing whitespace character at the end of any event (in addition to the <carriage-return> at the end of the line, removing the trailing whitespace character from each event will take care of that. (And, if there aren't any trailing whitespace characters at the end of individual events, trying to remove a trailing whitespace character won't hurt.)
# 18  
Old 10-26-2015
Oops. Actually, the middle segment above should be:
Code:
	REST="${REST%[[:space:]]}"
	for event in $REST
	do	event="${event%[[:space:]]}"
		[ ! "$event" ] && continue

This User Gave Thanks to Don Cragun For This Post:
# 19  
Old 10-26-2015
That is excellent Don
Thank you for your help
Much simpler than what I was envisaging.

All I have to do now is to understand it all so I can embed it in my brain for nest time

Ken
This User Gave Thanks to kcpoole For This Post:
# 20  
Old 10-26-2015
I'm glad to hear it is finally working for you.

Let us know if you can't figure out what any of those shell statements are doing.

- Don
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question