LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2007, 03:23 AM   #31
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324

I don't think I've actually used cygwin, but if it's running on MS, does cygwin use Unix line end endings (\n) or MS line endings (\r\n) ?
 
Old 10-11-2007, 04:09 PM   #32
daveoily
Member
 
Registered: Mar 2005
Distribution: ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
I wish I could say that I knew what you meant, personally I've not typed either (\n) or (\r\n)I will have a google around the subject sometime soon to help me understand better...

thanks anyway
 
Old 10-12-2007, 02:42 AM   #33
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
When text (aka ASCII or non-binary) are produced on Unix-like systems, there is an invisible end of line (aka newline or new record) marker, which (if you prog in eg C or Perl) is represented as '\n'.
On MS systems, the 'newline' is representd internally with \r\n instead, which is why you find utils like dos2unix to convert eg notepad output files to something Unix/Linux can handle.

HTH
 
Old 10-13-2007, 09:34 AM   #34
daveoily
Member
 
Registered: Mar 2005
Distribution: ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
ah! I think I see now well, at least a bit, that might explain why the script I wrote on my window$ system (in notepad) refuses to work on ubuntu, coincidentally enough at the end of the first line... hmmm...

I'll go and have a play with dos2unix and see if I can come up with something that works on ubuntu...

thanks for the hint
 
Old 10-13-2007, 02:10 PM   #35
daveoily
Member
 
Registered: Mar 2005
Distribution: ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
ok, I'm having problems getting dos2unix to run on my ubuntu, however, during my search, I ran into a little awk script that seems to (almost) make it work

Code:
awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt
I ran that on my ubuntu, and although it doesn't fully work yet, the resulting script at least performs the job partially, and (oddly) gets to a different filename before going funky
 
Old 12-19-2007, 04:59 AM   #36
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
Code:
tr -d '\r' < file.bak > file.txt
This command deletes \r from file.bak and saves the output to file.txt.
To test whether this problem is occuring in the original file do:
Code:
head -1 file.bak |od -c
 
Old 08-03-2008, 09:45 AM   #37
daveoily
Member
 
Registered: Mar 2005
Distribution: ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
Question hells teeth! what am I doing wrong now?

well, on and off, I've used this script for a while now, depending on how often I feel like putting more files on the server, it looks like apache now deals quite well with spaces, and thanks to some nice file renaming programs (thunar) and other things linuxy, I now have a much nicer file list.

when porting code from one windoze machine to linux (usually using ubuntu these days), I can open the wine version of notepad and cut and paste the text to a native linux files which takes care of the new record marker bit quite nicely

I don't remember altering the code, and the way I'm running it is just the same, so why would I start to get errors, I'm obviously doing something wrong, or I've forgotten how to use this the right way, could someone help me to remember how I do this please? ...

my code is this...
Code:
BEGIN{

print "<html>"

  print "<body>"

  print "<link rel=\"stylesheet\" type=\"text/css\" href=\"../1.css\">"

  print "<center>"

  print "<ul>"

}

{

  print "<li><a href=\""gensub(/\.mp3/ , ".html" , g )"\" target=\"rhs\">"$0"</a>"

  # and the other files ... 

  target = gensub(/\.mp3/ , ".html" , g )

  print "<html>" > target

  print "<body>" > target

  print "<link rel=\"stylesheet\" type=\"text/css\" href=\"../2.css\">" > target

  print "<center>" > target

  print "<a href=\"../music/"$0"\">"$0"</a>" > target

  print "</br>" > target

  print "</br>" > target

  print "<embed src=\""$0"\" autostart=\"true\">" > target

  print "</ul>" > target

  print "</center>" > target

  print "</body>" > target

  print "</html>" > target

  close( target )

}

END{

  print "</ul>"

  print "</center>"

  print "</body>"

  print "</html>"

}
and I run it thus...

Code:
c$ awk -f 1.awk list > index.html
awk: 1.awk: line 33: function gensub never defined
awk: 1.awk: line 33: function gensub never defined
gensub never defined??? It never seemed to bother with that line before!

And why tell me twice? am I really that bad that I need telling twice?

Clearly I am *hangs head in shame*

Help me sort this out please, it's got me stumped

Last edited by daveoily; 08-03-2008 at 10:32 AM.
 
Old 08-12-2008, 01:16 AM   #38
daveoily
Member
 
Registered: Mar 2005
Distribution: ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
Talking sorted!

sudo apt-get install gawk

did the trick
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting help arturhawkwing Linux - General 1 08-10-2006 12:54 PM
Bash scripting disruptive Programming 5 06-29-2006 04:49 PM
ls *.html bash scripting bhar0761 Linux - Newbie 15 09-21-2005 12:07 AM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 08:53 AM
BASH Scripting ? eroica Programming 3 06-07-2004 08:51 PM


All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration