For example I have this output:
string1 anynameveryveryverylong string2
string1 othernameveryveryverylong string2
I want truncate the name to the first ten characters:
string1 anynamever string2
string1 othernamev string2
a pseudo regex can be:
perl -pe "s/([^\t]+\t)([^\t]+)\t/\1\2{10}\t/g"
How do i get this?
^
matches at the start of the string\S
means non-whitespace+
means repeated at least once\s
means whitespace{10}
means repeated 10 timesI.e. Keep the first word and the first 10 characters of the following word while forgetting the remaining characters of the second word.
Your pseudoregex has one substantial problem: the
{10}
is placed in the replacement part, but the replacement is just a string. The regex happens in the pattern part only.Some more choices:
Perl with autosplitting on tabs:
awk
sed
One more Perl