Nargzul
asked on
Remove last \n in a file
Hi!
I must use a script, and the problem is that this script absolutly need in parameter a file, that have a liste of computer, one by line, the last line too.
I cannot modify the script.
The problem is that all program I've tried, add a \n at the end of the programm, and the script think there is a one computer more.
So I need to remove the last \n in file(under linux(ubuntu)), I'm open to all suggestion(awk/sed/any other programm).
Thanks for your help
I must use a script, and the problem is that this script absolutly need in parameter a file, that have a liste of computer, one by line, the last line too.
I cannot modify the script.
The problem is that all program I've tried, add a \n at the end of the programm, and the script think there is a one computer more.
So I need to remove the last \n in file(under linux(ubuntu)), I'm open to all suggestion(awk/sed/any other programm).
Thanks for your help
ASKER
Hum, I don't understand how it's can remove the last \n ???
Just edit the parameter file with whatever editor you like and remove the last blank line.
ASKER
I've tried, with vim, gedit, ... but after this, if you make a "cat", you see that the prompt comes a line after, because they all add this line.
can you provide sample file
ASKER
No probs
testfile.txt
testfile.txt
Can you show us the section of the script that reads the file. It must be doing something *very* strange indeed to give the behaviour you describe.
ASKER
I don't have it, I've a program already compiled in C++, given by a professor, and we must just touch parameter files.
awk '{if (NR == 1) printf("%s",$0); else printf("\n%s",$0)} file
Oops, missed out the trailing quote:
awk '{if (NR == 1) printf("%s",$0); else printf("\n%s",$0)}' file
This prints out the first line without its trailing newline, then precedes each subsequent line with a newline.
awk '{if (NR == 1) printf("%s",$0); else printf("\n%s",$0)}' file
This prints out the first line without its trailing newline, then precedes each subsequent line with a newline.
ASKER
I was thinking your script will works, but I don't understand, there is always a \n at the end of the file :/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The problem was that the furnished file has \r too, I've removed these, and thereafter I've used your command, I now it's all ok!
Thanks a lot!
Thanks a lot!
eg
Open in new window