0

I want to cut following string

abcd|xyz

number of characters before and afer pipe "|" symbol can vary.

I know cut command but it requires specific number 'from' and 'to' and i dont think will work here.

Can anyone help?

0

1 Answer 1

2

The command cut has the following parameters:

-d, --delimiter=DELIM   use DELIM instead of TAB for field delimiter
-f, --fields=LIST       select only these fields;  also print any line
                            that contains no delimiter character, unless
                            the -s option is specified

Following on from this, the below commands should do what you wish:

echo 'abcd|xyz' | cut -d'|' -f1   # Prints abcd
echo 'abcd|xyz' | cut -d'|' -f2   # Prints xyz
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.