Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Try:

awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answerthis answer)

Try:

awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Try:

awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Useless use of cat
Source Link
cuonglm
  • 158.5k
  • 41
  • 342
  • 421

Try:

cat testfile | awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Try:

cat testfile | awk '{ print length, $0 }' | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Try:

awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

added 91 characters in body
Source Link
Bichoy
  • 3.2k
  • 2
  • 22
  • 35

Try:

cat testfile | awk '{ print length, $0 }' | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Try:

cat testfile | awk '{ print length, $0 }' | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

Try:

cat testfile | awk '{ print length, $0 }' | sort -n | cut -d" " -f2- | head -1

The idea is to use awk to print the length of each line first. This will appear as:

echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text

Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.

(This was adopted from this answer)

Source Link
Bichoy
  • 3.2k
  • 2
  • 22
  • 35
Loading