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 11-05-2011, 03:10 AM   #1
cardioid1
LQ Newbie
 
Registered: Nov 2011
Distribution: Fedora
Posts: 1

Rep: Reputation: Disabled
How to specify an end-of-line value to head?


Hello all,

I'm trying to retrieve the first line from a few files which have 0x0d for EOL. I realize that I can simply have those values replaced with something recognizable; however, out of curiosity I would like to know if an EOL marker can be specified when invoking head.

Thanks in advance.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-05-2011, 03:59 AM   #2
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
http://www.linuxcommand.org/man_pages/head1.html

The manpage for head doesn't seem to suggest any way of changing the EOL. As a workaround, you can use tr to change all the 0x0d (return) characters to 0x0a (newline).

http://www.linuxcommand.org/man_pages/tr1.html

Here's an example where I do the opposite by converting from 0x0a to 0x0d.

Code:
echo -e "one\ntwo\nthree" | tr '\n' '\r' | hd
00000000  6f 6e 65 0d 74 77 6f 0d  74 68 72 65 65 0d        |one.two.three.|
You want the opposite, so try this instead:

Code:
tr '\r' '\n' < your_file.txt | head
HTH
 
1 members found this post helpful.
Old 11-05-2011, 03:47 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
If you're using bash, and all you need is to extract the first line, you can use read with the -d option.

Code:
read -d $'\r' line <file
echo "$line"
 
2 members found this post helpful.
  


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 Sort list by end of line to x position in each line? SilversleevesX Programming 14 08-19-2010 09:30 PM
head adds chars to end of each line (Red Hat Enterprise Linux) CheckiSt Linux - General 13 04-14-2010 04:52 AM
End-of-line Characters missing from last line of md5 file. Md5sum fails mehorter Linux - General 5 06-29-2009 09:56 PM


All times are GMT -5. The time now is 05:43 PM.

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