3

I have a file looks like:

input:

112 1 2 01 1 
000 0 0 22 0
122 2 2 22 0

I want to delete those columns in which there is less than 2 digits in each row. So the out should look like:

112 01
000 22
122 22

any suggestion? note that the real file is huge.

2

One possible way, with perl:

perl -alne 'print join " ", grep { length > 1 } @F' file
2

You can do this with sed (or more capable tools such as awk or perl).

For example

  sed -e :loop \
        -e 's/^[0-9]\{1\} //' \
        -e 's/ [0-9]\{1\}$//' \
        -e 's/ [0-9]\{1\} / /g' \
        -e 't loop' <input >output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.