I have many text files with certain problem. It gets fixed by doing vi and delete first line (supposedly a blank line) by pressing dd and save the file.
I need to automate this process and I tried sed '1d' samp.pgn and/or unix2dos / dos2unix etc. but NONE of them worked. Strange thing about these text files is that vi shows 4 lines and wc -l shows 3 lines.
What you have does not fit the definition of a text file. A non-empty text file's last character is (by definition) a <newline> character. It is also strange that your shell prompt appeared at the start of the next line after the cat; for common settings of PS1, the prompt should have appeared immediately after the Qc7 1-0 at the end of the last line of output instead of being on the next line.
If you know that you have a file that is missing the terminating <newline> character an easy way to fix it is:
If you have files where you don't know if the file has its terminating <newline> or not, and only want to add a <newline> to files that do not have the required terminator, you could try something like:
Note that this will not modify a file if it is not a regular file, is a regular file of size 0, and will not create a file if it doesn't exist.
This User Gave Thanks to Don Cragun For This Post:
Since the input is not a text file, the standards do not define the behavior of grep. On any system I've seen, this grep will remove the empty line. But on some systems it will add a trailing <newline> (as desired), and on other systems it will remove the partial line at the end of the file (not what the user wants).
From the description in the 1st message in this thread, it isn't obvious to me that the empty line at the start of the file is a problem. To me it sounded like there was an empty line at the start of the file, but the empty line wasn't the problem.
Making any change to the file in vi (such as x to delete a character and then u to undo the change) and then writing the file will cause most implementations of vi to add the missing trailing <newline>, but again, this is not required by the standards. (The behavior of vi is only specified when the file being edited is a text file.)
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Hello,
I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below:
# cat /tmp/passwd_sample
CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash
HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash... (4 Replies)
Hi ,
I need a help in following scenario.I tried searching in google but couldn't able to find the exact answer. Sorry if i am re-posting already answered query.
While i am trying to convert into log file into csv i couldn't able to get the format which i am looking for.
I converted file... (4 Replies)
Using KSH, I have one text file which just contains a list of distinct references on each line, e.g.;
123456789
987654321
15457544X
164450200
etc. The file will always be called "InputRefs.txt".
The number of distinct refs will be different each time.
For each line (distinct ref) I... (1 Reply)
Let me try my best to give you a picture of what I'm trying to do. Once again I'm sorry for the essay thats coming up.
I programmed a rather large library of script functions to deal with input, displaying ANSI block graphics, playing sounds, and refining the terminal and so on. I also designed... (8 Replies)
Folks pardon me for trivial question. After searching the entire forum i decided to post this question.
I have a file with some numbers with commas like this
123,456,789
If i open this textfile with either notepad or wordpad they ae looking absolutely fine. When I open this with excel file... (13 Replies)
this is utterly embarassing :(
after posting here i revisited my files and found that when i used "vi" instead of a gui based editor, i suddenly found that the indentations were in fact wrong :(
sorry about this :( (0 Replies)
Hello all:
I have a following textfile data with name inst1.txt
HDR|ABCD|10-13-2008 to 10-19-2008.txt|10-19-2008|XYZ
DTL|H|5464-1|0|02-02-2008|02-03-2008||||F|||||||||
DTL|D|5464-1|1|02-02-2008|02-03-2008|1||JJJ
DTL|D|5464-1|2|02-02-2008|02-03-2008|1||JJJ... (9 Replies)
Looking for a bit of help. I need to search for a string of words, but unfortunately these words are located on separate lines.
for example the text output is:
United
Chanmpions
Ronaldo
Liverpool
Losers
Torres
and my script code is
print("DEBUG - checking file message");
while... (15 Replies)