0

Ok first of all, i'm working in a VPS with Ubuntu 14.04.5 LTS

I'm trying to manipulate several text files with sed and my results aren't what it was suppose to be and i can't find a reason for that.. Even simple operations that worked to other users aren't working for me. Example: I have a file with a couple of thousand lines and with command-line i issue this sed command:

sed -n '/ID=stnr/,+1 p;/ID=stnr/,+1 p' /tmp/bigfile.txt >/tmp/filterfile.txt

this create a filterfile.txt with a few hundred lines. then i need to insert a 3rd file in the beginning of this one. And here it starts to get weird. nothing worked, i even tryed to insert a simple blank line

sed -i '1i\\' /tmp/filterfile.txt

is supposed to work, so it say's here i tried different variations

sed -i '1i\\' /tmp/filterfile.txt
awk 'BEGIN{print""}1' /tmp/filterfile.txt > /tmp/temp.txt
echo | cat - /tmp/filterfile.txt

but nothing worked! The file size goes from 88 669 to 88 670, but there is no new line in file. what am i doing wrong? am i missing some basic step ?

On another topic that i needed help here , the end code works fine but even that does not make a new line ... and @steeldriver said that my file can be unterminated... i really didn't understand it ... is there an additional step that i have to make after create a file with sed... ?? Is there a problem with my OS? At this point anything goes cause i'm really puzzled with this

edit: added /tmp/bigfile.txt - just a few more thousand lines like this

id=sdev user="jackinthebox" logged in ="18/04/2015" logged out= "18/04/2015"
alphanum=uufbhueklslnj
id=rgtj user="breakingeven" logged in ="17/04/2015" logged out= "17/04/2018"
alphanum=54ervbv45
id=stnr user="anotherme" logged in ="17/04/2015" logged out= "17/04/2018"
alphanum=oihj034fm
id=iorg user="nowayjose" logged in ="17/04/2015" logged out= "17/04/2018"
alphanum=ijpqw5wv6

then the /tmp/filterfile.txt:

id=stnr user="anotherme" logged in ="17/04/2015" logged out= "17/04/2018"
alphanum=oihj034fm

and finally the 3rd file

some random info 
  • Please add the output of file /tmp/bigfile.txt to your question – steeldriver Oct 8 '18 at 19:06
  • PS: after failing with the actual files i made the file exactly like above for testing – Lcross Portugal Oct 8 '18 at 19:25
  • know i just noted something strange, 1st time i ran the command it does nothing 2nd time it adds 2 new lines.... – Lcross Portugal Oct 8 '18 at 20:13
1

Ok i just found what was wrong and i think i know what @steeldriver meant

the original file was created in Windows... so before it was "handled" by var, it should be converted do unix format (i used dos2unix). hope it helps someone...

  • Yes that indeed was what I suspected - hence my suggestion to run the file command which (among other things) might have indicated ... with CRLF line terminators – steeldriver Oct 8 '18 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.