Optimize a combination of commands

Im currently running this command to satisfy a particular task. it works for my purposes. but i want to be able to optimize this string of commands and have it be reduced to 1 or 2 commands, if at all possible:

head -4 datafile 2>/dev/null | cut -c1-400 | wc | awk '{print $2$1$3}'

I don't see why a single awk command couldn't do all of that, although whether it would be quicker, I doubt.

And wc only returns 4 fields, at least as far as I see, so not sure what $5 in your awk gives you.

Not sure that pipe makes any sense at all. wc in a pipe prints three fields (four if operating on file parameters), so the following awk doesn't have a $5 to print.
WHAT exactly do you want to achieve?

the

$5 

was meant to be

$2

. I have changed it.

That doesn't answer the questions that have been asked. What are you trying to do?

In what way does converting output from wc , such as:

   18428  115732  794534

into:

11573218428794534

perform any useful purpose?

Just for the fun of it - as the original spec for me is unintelligible - this would yield the same, incomprehensible result:

awk '{$0 = substr ($0,1,400); TNF += NF; TC += length} NR==4 {exit} END {print TNF NR TC+NR}' datafile
1 Like