Sed command dropping last record in File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed command dropping last record in File
# 1  
Old 09-11-2008
Sed command dropping last record in File

Hello:
I wrote a sed statement that is inserting 3 variables at the beginning of each record in a comma-delimited file:

for FILE in *gnrc_lkup.csv
do
c=`echo $FILE | cut -c1-3`
d=`grep $c $RTLIST | cut -c4-6`
e=`grep $c $RTLIST | cut -c7`
f=`grep $c $RTLIST | cut -c8`
sed -e 's/^/'$d','$e','$f',/' < $FILE > $FILE.new
done

However, after further testing, I noticed that the
last record is being removed. Can someone tell me what part of the sed statment above would be doing this and how it can be corrected?

Any input is appreciated.
Thank you,
Brett
# 2  
Old 09-11-2008
Is there a newline at the end of the file?

If not, it is not a valid text file, and sed only works with text files.
# 3  
Old 09-11-2008
Thank you cfajohnson for the reply.

There is no newline at the end. I think
during editing it got removed. Even though this was not a valid text file by your definition, do you know why the sed command would work
on all but the last data record which it removed? Your input is appreciated. Thanks, Brett
# 4  
Old 09-11-2008
I repeat:

Quote:
sed only works with text files.
# 5  
Old 09-11-2008
So put a newline at the end and its now a "text" file and it should work.

I would ASSume that it looks for a "newline" before processing the line, so if its not there it excludes the whole line.
# 6  
Old 09-11-2008
Thanks again for the reply cfajohson
Thanks ikon for replying.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

awk command to retrieve record 23 and 89 from UNIX file

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 am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies

2. UNIX for Beginners Questions & Answers

awk command to retrieve record 23 and 89 from UNIX file

Hi Everyone, I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this? Regards Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

3. Red Hat

Create same file name to directory name without dropping it

Hi, Under '/home' directory, there is one file called 'maddy'.Usually there used to be directories under /home directory. # ls -alrt total 132 drwx------ 2 hcladmin sys 4096 May 30 10:54 admin drwxr-xr-x 29 root root 4096 Aug 27 03:54 .. drwx------ 2 v6admin dba ... (3 Replies)
Discussion started by: Maddy123
3 Replies

4. Shell Programming and Scripting

awk command to omit trailer record in a file

I am trying to omit the trailer record in a variable width file I tried using awk 'NR >1 { print prev } { prev = $0 }' filename The above command is giving output but somehow it is trimming columns from the record. For example if my record has columns A,B,C,D The awk gives output as A,B,C ... (4 Replies)
Discussion started by: abhilashnair
4 Replies

5. Shell Programming and Scripting

sed and awk not working on a large record file

Hi All, I have a very large single record file. abc;date||bcd;efg|......... pqr;stu||record_count;date when i do wc -l on this file it gives me "0" records, coz of missing line feed. my problem is there is an extra pipe that is coming at the end of this record like... (6 Replies)
Discussion started by: Gurkamal83
6 Replies

6. Shell Programming and Scripting

Read .txt file and dropping lines starting with #

Hi All, I have a .txt file with some contents as below: Hi How are you? # Fine and you? I want a script file which reads the .txt file and output the lines which does not start with #. Hi How are you? Help is highly appreciated. Please use code tags when posting data and... (5 Replies)
Discussion started by: bghosh
5 Replies

7. UNIX for Dummies Questions & Answers

Need a command to get part of a record from file

I have a file which contains a record like follows /dir1/dir2/dir3/file.dat I need command so that output can be only file.dat (4 Replies)
Discussion started by: sreenusola
4 Replies

8. UNIX for Dummies Questions & Answers

Record count problem using sed command

Hi, I have a script which removes 2 header records and 1 trailer record in a list of files. The commands doing the actions are sed '1,2d' $file > tempfile1.dat sed '$d' < tempfile1.dat > $output.txt Its working fine for all records except a file having size=1445509814 and number of... (2 Replies)
Discussion started by: ayanbiswas
2 Replies

9. Shell Programming and Scripting

Usiung last record of file using 'sed' command

Hi, In my Scripts,i need to read record from a file and after reading I need to delete that record,as I need to run the script in a loop for no of records in file.( I am using While-do command for that).But my problem is while deleting record using command"`cat ${TEST_FILE}|sed '$d' >... (5 Replies)
Discussion started by: Roopanwita
5 Replies

10. UNIX for Dummies Questions & Answers

command to remove last record on file

Hi, First time on the forum. I have converted some files using the Unix to DOS command but need to strip off the last record that is generated from this conversion that contains just a ^Z. Is there any command that would accomplish this without having to do stream editing? (4 Replies)
Discussion started by: mheinen
4 Replies
Login or Register to Ask a Question