Write an alias to search a file for a specific term car and

Write an alias to search a file for a specific term (car) and sort the output by string length.

(Include the shell code to produce the results). In your answers show a specific example which demonstrates that your script works as desired.

Update: This could be done in any language, maybe Java or C++

Solution

shell script-

#!/bin/bash
alias search=\"grep -H -R \"car\" ./ | cut -d: -f1 | awk \'{ print length, $0;}\' | sort -n\"
search

for example,
1.\"car\" term contains in files abc and abcd, then grep would result in
abc : car
abcd : car

2. then next piped command cut will give result
abc
abcd

3. awk would calculate the length of the given strings and sort will give result in ascending order.
abc
abcd

4. if u want sorting in descending order just use command \'sort -nr\'

  for example,  

for example,
1.\"car\" term contains in files abc and abcd, then grep would result in
abc : car
abcd : car

2. then next piped command cut will give result
abc
abcd

3. awk would calculate the length of the given strings and sort will give result in ascending order.
abc
abcd

4. if u want sorting in descending order just use command \'sort -nr\'

Write an alias to search a file for a specific term (car) and sort the output by string length. (Include the shell code to produce the results). In your answers

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site