07-07-2006
How to delete a character at the end of a file.
I am having a file which has data like this:-
1,2,3,4,5,
But I need to remove the last comma from this file. So the data should be like
1,2,3,4,5
The command I tried was
temp=`cat ${FileName}.txt`
len=`awk '{print length($0)}' ${FileName}.txt`
len=`expr $len - 1`
temp=`expr substr $temp 1 $len`
The problem here i am facing is if the data inside the file is very huge (say 1,2,3,4......9999,10000,)then it is giving error because the command (len=`awk '{print length($0)}' ${FileName}.txt`) returns two values for the variable like
len=10239
8651
Due to this the subsequent command fails.
Any help in this regard please.
Thanks & Regards,
Rony
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies
2. UNIX for Dummies Questions & Answers
Hello all
How can I insert character to the end of text file without opening it in vi
Just simple one liner, can it be done?
Tnx (1 Reply)
Discussion started by: umen
1 Replies
3. UNIX for Dummies Questions & Answers
hi all, i have this question: How to add new line character at the end of a file????
i need this because i am loading a file to sybase and i have problems with the last record
thanks for your help (5 Replies)
Discussion started by: DebianJ
5 Replies
4. Shell Programming and Scripting
Hi,
i want to append a character '|' at end of each line of a file abc.txt.
for example if the file abc.txt conatins:
a|b|c
1|2|33
w|2|11
i want result file xyz.txt
a|b|c|
1|2|33|
w|2|11|
I know this is simple but sumhow i am not able to reach end of line.
its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies
5. Shell Programming and Scripting
hi all
i have 32 lines in file. the length of each line is 82 , i want that in the end of each line , means in postion 83-84 to put two characters 0d(=\015), 0a(=\012)
i want that the 0d will be in postion 83
and the 0a will be in postion 84
in each line of the file
how shall i do it ?
... (7 Replies)
Discussion started by: naamas03
7 Replies
6. Shell Programming and Scripting
Hi All
I have a file which conatins record.the length of every records is 47.
problem : in the end of record i don't have a "\015" character.
i want to add this "\015" charcter in the end of every record.
the file contains something like 700 records.
i've tried with sed command - nothing.
... (8 Replies)
Discussion started by: naamas03
8 Replies
7. Shell Programming and Scripting
I need to remove new line character from end of file.
Suppose here are content.
a|b|c|d|r
a|b|c|d|r
a|b|c|d|r
<new line>
that means file contains 4 lines but data is there in 3 lines.
so I want that only 3 lines should be there in file.
Please help (20 Replies)
Discussion started by: varun940
20 Replies
8. Shell Programming and Scripting
Hi All,
I have following piece of code in UNIX C Shell script and I want to add one more command which can add newline at the end of file only if there is no newline character exists.
foreach file (`ls $dd_PLAYCARD_EDI_IN`)
if ( -f $dd_PLAYCARD_EDI_IN/${file} ) then
cat -n... (4 Replies)
Discussion started by: jnrohit2k
4 Replies
9. Shell Programming and Scripting
Hi Gurus,
Need help. I'm a beginner in Unix. I have a requirement, need to add or append newline (\n) character in file.
Sample Data:
1|Main|Test|~#
2|Main|Hello|~#
3|Main|Unix|~#
4|Main|File|~#Output:
1|Main|Test|~#
2|Main|Hello|~#
3|Main|Unix|~#
4|Main|File|~#\n -- append only... (13 Replies)
Discussion started by: Gouri Solleti
13 Replies
10. Shell Programming and Scripting
I will appreciate if you help me here in this script in Solaris Enviroment.
Scenario:
i have 2 files :
1) /tmp/TRANSACTIONS_DAILY_20180730.txt:
201807300000000004
201807300000000005
201807300000000006
201807300000000007
201807300000000008
2)... (10 Replies)
Discussion started by: teokon90
10 Replies
case(3) Library Functions Manual case(3)
NAME
case - convert ASCII uppercase bytes to lowercase
SYNTAX
#include <case.h>
void case_lowers(s);
void case_lowerb(s,len);
int case_diffs(s,t);
int case_equals(s,t);
int case_starts(s,t);
int case_diffb(s,len,t);
int case_startb(s,len,t);
char *s;
char *t;
unsigned int len;
DESCRIPTION
case_lowers converts each uppercase byte in the string s to lowercase. s must be 0-terminated.
case_lowerb converts each uppercase byte in the buffer s, of length len, to lowercase.
case_diffs lexicographically compares lowercase versions of the strings s and t. It returns something positive, negative, or zero when the
first is larger than, smaller than, or equal to the second. s and t must be 0-terminated.
case_equals means !case_diffs.
case_starts returns 1 if a lowercase version of s starts with a lowercase version of t. s and t must be 0-terminated.
case_diffb lexicographically compares lowercase versions of the buffers s and t, each of length len. It returns something positive, nega-
tive, or zero when the first is larger than, smaller than, or equal to the second.
case_startb returns 1 if a lowercase version of the buffer s, of length len, starts with a lowercase version of the string t. t must be
0-terminated.
The case routines are ASCII-specific. They are suitable for programs that handle case-independent networking protocols.
All comparisons are performed on unsigned bytes.
SEE ALSO
byte_diff(3), byte_equal(3), str_diff(3), str_equal(3), str_start(3)
case(3)