Not able to read .csv file until open in vi editor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to read .csv file until open in vi editor
# 1  
Old 11-23-2013
Not able to read .csv file until open in vi editor

Hi,

I am facing a problem regarding .csv file, my script does not read .csv file and if i open this file in vi editor and perform :wq option then only my script reads the .csv file.

Thanks
# 2  
Old 11-23-2013
How does your script access your .csv file?

What error messages does your script produce when it tries to read your .csv file?

What is the output from the command ls -l file.csv (assuming your .csv file is named file.csv) before and after you update file.csv using vi?
# 3  
Old 11-23-2013
Hi,

below is the code i am using

Code:
#!/usr/bin/bash

while read each_line
do
var_tcode=`echo $each_line | awk -F',' '{print $1}'`

done < WPA_20131120_APP0000108.csv

echo "Value:: "$var_tcode

i have a file "WPA_20131120_APP0000108.csv" having below data
Code:
CE2DD,00000000108,00000000108,,20.11.2013,2.38.00.00.100010,20.00,MVR,Web Payment

when i run the above script it does not print any thing but when i open the same .csv file in vi editor and exit with :wq option and i run the script it prints CE2DD

Is there some problem in .csv file format or permission??

Last edited by Don Cragun; 11-23-2013 at 05:53 AM.. Reason: Fix CODE tags.
# 4  
Old 11-23-2013
It sounds like whatever is creating your .csv files is not adding the proper line terminator (a newline character) at the end of the file. Then, when you open the file with vi and re-write it, vi adds the newline for you.

To verify this, use:
Code:
od -bc file.csv

to examine the contents of a .csv file that is not producing any output from your bash script. Then re-write your file using vi and run the above od command again. I expect that the last character in your .csv file displayed by od will change.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 11-23-2013
Code:
echo "CE2DD,00000000108,00000000108,,20.11.2013,2.38.00.00.100010,20.00,MVR,Web Payment" > WPA.csv

Code:
 awk -F, '{print $1}' WPA.csv

Output:
Code:
CE2DD

In your case, how WPA_20131120_APP0000108.csv file is written ?
Can you post the output of ls -l WPA_20131120_APP0000108.csv as Don asked earlier ?

I dont think,it can be a permission issue .
# 6  
Old 11-23-2013
i got it , Thnkyou so much ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check if a file is open in editor?

Hi there! I'm developing a program that allows the user to open and edit files using both an editor and the terminal. Once the user has finished editing the file an update is sent to the logbook that compares the file before and after it was edited - this can only be done if the file is closed (I... (23 Replies)
Discussion started by: cherryTango
23 Replies

2. Shell Programming and Scripting

Read .csv file

Hello, this is my very first comment on this forum and i hope i don't mess it up. If i do, please forgive me (also for any language mistakes you may wanna know that i'm not native speaking). As i just started doing a bigger paper for my studies i got a bunch of data in seperate csv-files... (1 Reply)
Discussion started by: FabianDe
1 Replies

3. Shell Programming and Scripting

Read csv file in bash

how to I use IFS to read 2 files (csv) and run the followiung script ./naviseccli -h 1.2.3.4 storagegroup -addhlu -gname $hostname -hlu $hlu_num -alu $alu_num the csv file for $hostname is host1 host2 . . . for hlu and alu its alu,hlu (2 Replies)
Discussion started by: tdubb123
2 Replies

4. UNIX and Linux Applications

Notepad++ hang when open file edited in other text editor

Hi, I would like to ask about the notepad++ text editor application, Although there are alternative and more great text editor in linux (gedit, geany, jedit) im still using the notepad++ sometimes cause for some of my own reason one of those is the minimalist text(what i mean is notepad++ has a... (2 Replies)
Discussion started by: jao_madn
2 Replies

5. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

6. Shell Programming and Scripting

read .csv file

Need UNIX script read below .csv file and print the line only records where type = TRN. Srno,Type,InputFileName,NewColumnData 1,TRN,File1.dat,11 2,TRN,File2.dat,12 3,TRN,File3.dat,13 4,REF,File4.dat, 5,REF,File5.dat, regards, santosh (4 Replies)
Discussion started by: santosh2k2
4 Replies

7. Shell Programming and Scripting

Read Csv file

Hi All, I need to check if a csv file is empty, leaving the first line as the first line is header pls help Thanks (3 Replies)
Discussion started by: gwrm
3 Replies

8. UNIX for Dummies Questions & Answers

How to open file in VI Editor at a specific line?

i have following query e.g i want the VI Editor cursor at line number N instead of 0 while opening the file from unix prompt. vi filename ?????? Can anyone help? (4 Replies)
Discussion started by: skyineyes
4 Replies

9. Shell Programming and Scripting

How to give permissions to an open file in vi editor?

Hi all, I have a shell script that i started editing, only in the midst of which i tried to save the changes i found that the file wasnt been provided with write/execute permissions. I later have redone the changes and saved the file- Just curious to know if there was any command wherein... (5 Replies)
Discussion started by: Pankajakshan
5 Replies

10. UNIX for Dummies Questions & Answers

How do u open a read only file in Unix?

How do u open a read only file in Unix? (1 Reply)
Discussion started by: JosephGerard
1 Replies
Login or Register to Ask a Question