Rectangle 27 7

On Mac, head -n -1 wont work. And, I was trying to find a simple solution [ without worrying about processing time ] to solve this problem only using "head" and/or "tail" commands.

I tried the following sequence of commands and was happy that I could solve it just using "tail" command [ with the options available on Mac ]. So, if you are on Mac, and want to use only "tail" to solve this problem, you can use this command :

1> tail -r : simply reverses the order of lines in its input

2> tail -n +2 : this prints all the lines starting from the second line in its input

Remove the last line from a file in Bash - Stack Overflow

bash command-line scripting truncate
Rectangle 27 5

On Mac, head -n -1 wont work. And, I was trying to find a simple solution [ without worrying about processing time ] to solve this problem only using "head" and/or "tail" commands.

I tried the following sequence of commands and was happy that I could solve it just using "tail" command [ with the options available on Mac ]. So, if you are on Mac, and want to use only "tail" to solve this problem, you can use this command :

1> tail -r : simply reverses the order of lines in its input

2> tail -n +2 : this prints all the lines starting from the second line in its input

Remove the last line from a file in Bash - Stack Overflow

bash command-line scripting truncate
Rectangle 27 13

Here are the built-in ways to do head and tail. Don't use pipes because if you have a large file, it will be extremely slow. Using these built-in options will be extremely fast even for huge files.

gc log.txt -head 10 
gc log.txt -tail 10
gc log.txt -tail 10 -wait # equivalent to tail -f

but Joey's comment seems to indicate the exact opposite! how do I know who to trust or which (built-in) method is most efficient?

@NH My answer is in agreement with Joey's comment. His comment says "-Last is slow... That's why Get-Content -Tail exists." | select -last uses pipes. I'm using -tail without pipes. But if you do ever find two conflicting answers, you could probably trust the person with a much higher reputation. Also, you can simply try the two methods on a large file. It will be very obvious on a large file.

Got it. Sorry, I must have been confused the first time I read the posts.

windows - How to do what head, tail, more, less, sed do in Powershell?...

windows powershell
Rectangle 27 1

You can do it using just head and tail ...

NR=3; cat test.txt | head -n $NR | tail -n -1

extracts line 3 from test.txt; and

NB=2; NR=3; cat test.txt | head -n $(expr $NR \+ $NB) | tail -n -$NB

perl - Get a specific line of a file in Unix - Stack Overflow

perl shell unix awk sed
Rectangle 27 4

You can do this using the head and tail commands:

head -n <num> | tail -n <lines to print>

where num is 1e6 + the number of lines you want to print.

Not the most efficient answer since you'd need to do a "wc -l" on the file to get a line count, followed by an addition to add the million :-). You can do it with just "tail".

I'm not sure, my understanding was that 1e6 would be known at the time of calling. Counting backwards isn't the fastest though.

linux - Print a file skipping X lines in Bash - Stack Overflow

linux bash printing skip
Rectangle 27 4

You can do this using the head and tail commands:

head -n <num> | tail -n <lines to print>

where num is 1e6 + the number of lines you want to print.

Not the most efficient answer since you'd need to do a "wc -l" on the file to get a line count, followed by an addition to add the million :-). You can do it with just "tail".

I'm not sure, my understanding was that 1e6 would be known at the time of calling. Counting backwards isn't the fastest though.

linux - Print a file skipping X lines in Bash - Stack Overflow

linux bash printing skip
Rectangle 27 21

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via @ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.

So, search for a

<head>
    <title>Some title</title>
    ...
</head>

in your templates and replace it by

<h:head>
    <title>Some title</title>
    ...
</h:head>

OK, now the error message disappeared but PrimeFaces and Crud still run separately!

Just press "Ask Question" button to ask a question about that if you need answers. The current question has already been answered.

user interface - One or more resources has the target of 'head' but no...

user-interface jsf primefaces head
Rectangle 27 21

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via @ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.

So, search for a

<head>
    <title>Some title</title>
    ...
</head>

in your templates and replace it by

<h:head>
    <title>Some title</title>
    ...
</h:head>

OK, now the error message disappeared but PrimeFaces and Crud still run separately!

Just press "Ask Question" button to ask a question about that if you need answers. The current question has already been answered.

user interface - One or more resources has the target of 'head' but no...

user-interface jsf primefaces head
Rectangle 27 21

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via @ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.

So, search for a

<head>
    <title>Some title</title>
    ...
</head>

in your templates and replace it by

<h:head>
    <title>Some title</title>
    ...
</h:head>

OK, now the error message disappeared but PrimeFaces and Crud still run separately!

Just press "Ask Question" button to ask a question about that if you need answers. The current question has already been answered.

user interface - One or more resources has the target of 'head' but no...

user-interface jsf primefaces head
Rectangle 27 21

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via @ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.

So, search for a

<head>
    <title>Some title</title>
    ...
</head>

in your templates and replace it by

<h:head>
    <title>Some title</title>
    ...
</h:head>

OK, now the error message disappeared but PrimeFaces and Crud still run separately!

Just press "Ask Question" button to ask a question about that if you need answers. The current question has already been answered.

user interface - One or more resources has the target of 'head' but no...

user-interface jsf primefaces head
Rectangle 27 21

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via @ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.

So, search for a

<head>
    <title>Some title</title>
    ...
</head>

in your templates and replace it by

<h:head>
    <title>Some title</title>
    ...
</h:head>

OK, now the error message disappeared but PrimeFaces and Crud still run separately!

Just press "Ask Question" button to ask a question about that if you need answers. The current question has already been answered.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

user interface - One or more resources has the target of 'head' but no...

user-interface jsf primefaces head
Rectangle 27 3

you can use this simple command instead of using a for loop,

ls -ltr | awk '{print $9}' | xargs head

unix - cat multiple files but include filename as headers - Stack Over...

unix header terminal concatenation cat
Rectangle 27 3

you can use this simple command instead of using a for loop,

ls -ltr | awk '{print $9}' | xargs head

unix - cat multiple files but include filename as headers - Stack Over...

unix header terminal concatenation cat
Rectangle 27 8

Can you use unix commands? I think using head -1 and tail -n 1 are probably the most efficient methods. Alternatively, you could use a simple fid.readline() to get the first line and fid.readlines()[-1], but that may take too much memory.

Hmm would creating a subprocess to execute these commands be the most efficient way then?

+1 for head -1 and tail -1. fid.readlines()[-1] is not a good solution for huge files.

os.popen("tail -n 1 %s" % filename).read()

python - What is the most efficient way to get first and last line of ...

python file seek
Rectangle 27 4

In your R console, when you type head(m, 5), what you see printed on your screen is really the result of print(head(m, 5)). So if this is what you want your output to look like, consider using the print function rather than cat when displaying the head and tail of your objects:

ht <- function(d, m=5, n=m) {
  # print the head and tail together
  cat("head -->\n")
  print(head(d,m))
  cat("--------\n")
  cat("tail -->\n")
  print(tail(d,n))
}

m <- matrix(1:10, 20)
ht(m)
# head -->
#      [,1]
# [1,]    1
# [2,]    2
# [3,]    3
# [4,]    4
# [5,]    5
# --------
# tail -->
#       [,1]
# [16,]    6
# [17,]    7
# [18,]    8
# [19,]    9
# [20,]   10

I find @mrdwab's answer to be a very elegant solution. It does not explicitly use print, instead returns a list. However, when his function is called from the R console and the output is not assigned to anything, then it is printed to the console (hence print is used implicitly). I hope that helps you understand what's going on.

Thanks, that helps a lot. I note that head and tail in utils have methods for ftable, table and function - will this approach handle all these cases also? (i am afk, so cannot check just now - but wanted to comment to say thankyou for explaining).

Yes, anything for which there are both head and tail methods.

dataframe - combining head and tail methods in R - Stack Overflow

r dataframe tail head cat
Rectangle 27 2

You can use HeaderTemplate property to setup the head programatically or use ListView instead if you are using .NET 3.5.

asp.net - GridView - Show headers on empty data source - Stack Overflo...

asp.net gridview header
Rectangle 27 102

urllib2 can be used to perform a HEAD request. This is a little nicer than using httplib since urllib2 parses the URL for you instead of requiring you to split the URL into host name and path.

>>> import urllib2
>>> class HeadRequest(urllib2.Request):
...     def get_method(self):
...         return "HEAD"
... 
>>> response = urllib2.urlopen(HeadRequest("http://google.com/index.html"))

Headers are available via response.info() as before. Interestingly, you can find the URL that you were redirected to:

>>> print response.geturl()
http://www.google.com.au/index.html

response.info().__str__() will return string format of the header, in case you want to do something with the result you get.

except that trying this with python 2.7.1 (ubuntu natty), if there's a redirect, it does a GET on the destination, not a HEAD...

That's the advantage of the httplib.HTTPConnection, which doesn't handle redirects automatically.

but with doshea's answer. how to set the timeout? How to handle bad URLs, i.e., URLs that are not no longer alive.

How do you send a HEAD HTTP request in Python 2? - Stack Overflow

python python-2.7 http http-headers content-type
Rectangle 27 102

urllib2 can be used to perform a HEAD request. This is a little nicer than using httplib since urllib2 parses the URL for you instead of requiring you to split the URL into host name and path.

>>> import urllib2
>>> class HeadRequest(urllib2.Request):
...     def get_method(self):
...         return "HEAD"
... 
>>> response = urllib2.urlopen(HeadRequest("http://google.com/index.html"))

Headers are available via response.info() as before. Interestingly, you can find the URL that you were redirected to:

>>> print response.geturl()
http://www.google.com.au/index.html

response.info().__str__() will return string format of the header, in case you want to do something with the result you get.

except that trying this with python 2.7.1 (ubuntu natty), if there's a redirect, it does a GET on the destination, not a HEAD...

That's the advantage of the httplib.HTTPConnection, which doesn't handle redirects automatically.

but with doshea's answer. how to set the timeout? How to handle bad URLs, i.e., URLs that are not no longer alive.

How do you send a HEAD HTTP request in Python 2? - Stack Overflow

python python-2.7 http http-headers content-type
Rectangle 27 102

urllib2 can be used to perform a HEAD request. This is a little nicer than using httplib since urllib2 parses the URL for you instead of requiring you to split the URL into host name and path.

>>> import urllib2
>>> class HeadRequest(urllib2.Request):
...     def get_method(self):
...         return "HEAD"
... 
>>> response = urllib2.urlopen(HeadRequest("http://google.com/index.html"))

Headers are available via response.info() as before. Interestingly, you can find the URL that you were redirected to:

>>> print response.geturl()
http://www.google.com.au/index.html

response.info().__str__() will return string format of the header, in case you want to do something with the result you get.

except that trying this with python 2.7.1 (ubuntu natty), if there's a redirect, it does a GET on the destination, not a HEAD...

That's the advantage of the httplib.HTTPConnection, which doesn't handle redirects automatically.

but with doshea's answer. how to set the timeout? How to handle bad URLs, i.e., URLs that are not no longer alive.

How do you send a HEAD HTTP request in Python 2? - Stack Overflow

python python-2.7 http http-headers content-type
Rectangle 27 102

urllib2 can be used to perform a HEAD request. This is a little nicer than using httplib since urllib2 parses the URL for you instead of requiring you to split the URL into host name and path.

>>> import urllib2
>>> class HeadRequest(urllib2.Request):
...     def get_method(self):
...         return "HEAD"
... 
>>> response = urllib2.urlopen(HeadRequest("http://google.com/index.html"))

Headers are available via response.info() as before. Interestingly, you can find the URL that you were redirected to:

>>> print response.geturl()
http://www.google.com.au/index.html

response.info().__str__() will return string format of the header, in case you want to do something with the result you get.

except that trying this with python 2.7.1 (ubuntu natty), if there's a redirect, it does a GET on the destination, not a HEAD...

That's the advantage of the httplib.HTTPConnection, which doesn't handle redirects automatically.

but with doshea's answer. how to set the timeout? How to handle bad URLs, i.e., URLs that are not no longer alive.

How do you send a HEAD HTTP request in Python 2? - Stack Overflow

python python-2.7 http http-headers content-type