Last line omit


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Last line omit
# 1  
Old 05-15-2013
Last line omit

I have a csv file "file.csv" which has 5 records but when I check record count for file.csv in unix it shows as 6, the last line is empty and I need to omit and need for processing.
Kindly help.

Thanks

Last edited by Scott; 05-15-2013 at 03:24 AM.. Reason: Moved thread. Not an AIX-specific question
# 2  
Old 05-15-2013
You could try:
Code:
$ grep -vc ^$ file.csv

depending on the definition of "empty" and, of course, an assumption that a row in a CSV file with no values still is written with delimiters.
# 3  
Old 05-15-2013
If you just want to get rid of empty lines use grep sed awk any..

Code:
 
grep -v "^$" filename
sed '/^$/d' filename
awk '!/^$/{print}' filename

# 4  
Old 05-15-2013
To unconditionally omit the last line:
Code:
sed '$d'

Regards,
Alister
# 5  
Old 05-15-2013
It is working with .txt files but not with .csv files
# 6  
Old 05-15-2013
Unix doesnt diff between .txt or .csv

Can you please post the output of cat -vet <<your.csv>>?
# 7  
Old 05-15-2013
Sorry, its a sensitive dat. A '$' symbol is getting appended at the end of each line.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Rsync - hot to omit MOTD/banners

I'm working on an rsync script and I'd like it to omit the MOTD banners and NOT output them to the file. I tried the --no-motd argument in the command but for some reason the MOTD still continues to appear. Can anyone advise? (10 Replies)
Discussion started by: infrared013
10 Replies

2. Shell Programming and Scripting

Combine/omit data from 2 files

i made a script on my own. this is for the inventory to all of my AWS servers, and i run it to all of my servers to get the hostname, please look at file2. Then i need some data in file3 as well,. i need to combine them #cat file1 192.10.1.41 server.age.com ###### 192.10.0.40 ssh cant... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

3. Shell Programming and Scripting

how to omit the output of the at now command

Hi Everyone, I'm invoking the following command by a script: at now < /home/d01plmi1/rep/start_replication.sh > /dev/null/ 2>&1 but everytime is runs it put a message into the mail box of the userid executing the command. How can I redirect this so I can stop these notifications... (4 Replies)
Discussion started by: arizah
4 Replies

4. Shell Programming and Scripting

How to omit a part of the string

I have a file, f1 with content: File f1: abc_English_Dlr def_123_English_Dlr qwe_98_yu_English_Dlr dsw_1_English_Dlr I want to remove "_English_Dlr" from it. I used cut command but the problem is there may be a case for getting 1 or more fields before _English_Dlr . So Cut... (8 Replies)
Discussion started by: karumudi7
8 Replies

5. Shell Programming and Scripting

using awk to omit certain characters

I have a file called file.txt with multiple lines in them. I'm trying to remove the first 2 characters and the last 2 with awk. '.batman') '.superman') '.dragonheart') .'superduper') I tried doing the following and able to get rid of the first two characters. How do I remove the trailing... (5 Replies)
Discussion started by: zerofire123
5 Replies

6. UNIX for Dummies Questions & Answers

omit strings from grep result

Hi, I know this is a really dumb question, and I used to know how to do this, but I forgot and I can't seem to find the command online anywhere: When I grep a string, how do I filter the results so that lines containing a certain string are OMITTED! for example: grep 'string' *.txt ... (2 Replies)
Discussion started by: juliette salexa
2 Replies

7. Shell Programming and Scripting

Omit Blank Lines while comparing two files.

Hello All, I am writting file comparison Utility and I have encountered such a senario where there are 2 files such as follows- 1#!/usr/local/bin/python 2 import gsd.scripts.admin.control.gsdPageEscalate 3.gsd.scripts.admin.control.gsdPageEscalate.main() 1 #!/usr/local/bin/python... (10 Replies)
Discussion started by: Veenak15
10 Replies

8. Shell Programming and Scripting

how to omit data from a file created in a script

I am using the fallowing script. this script seems to work fine except the file has data I do not wish to have. Is there away to omit that data. I will first provide the scrip and then a sample of the data the way it looks and then a sample of how I would like the data to look. Thanks for any... (3 Replies)
Discussion started by: krisarmstrong
3 Replies

9. Shell Programming and Scripting

Command to list only files omit directories.

Hi All I am writting a script that does a comparison between files in 2 diffectent directories. To do this I need a command that will list out only the files in a give directory and omit any sub dorectories with that directory. But I am unable to find it. Please Help. I tried ls... (5 Replies)
Discussion started by: Veenak15
5 Replies

10. UNIX for Dummies Questions & Answers

Omit repeating lines

Can someone help me with the following 2 objectives? 1) The following command is just an example. It gets a list of all print jobs. From there I am trying to extract the printer name. It works with the following command: lpstat -W "completed" -o | awk -F- '{ print $1}' Problem is, I want... (6 Replies)
Discussion started by: TheCrunge
6 Replies
Login or Register to Ask a Question