Command to get first 5 and last 10 characters of a line Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Command to get first 5 and last 10 characters of a line without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have the following line:

postgres  3625     1  0 Jan31 ?        00:00:35 /opt/rh/rh-postgresql95/root/usr/bin/postgres -D /var/opt/rh/rh-postgresql95/lib/pgsql/data

Please give a command to cut the first 5 characters and last 10 characters and concatenate them in a single line command.

Answer

You can feed the line into Perl, like this:

$ printf "%s" {a..z} | perl -nlE'say substr($_,0,5) . substr($_,-10)'
abcdeqrstuvwxyz
We are here to answer your question about Command to get first 5 and last 10 characters of a line - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji