1

I'm using ksh script to determine what the delimiter in a file is using awk. I know this delimiter will always be in the 4 position on the first line. The issue I'm having is that the character being used as in a delimiter in a particular file is a * and so instead of returning * in the variable the script is returning a file list. Here is sample text in my file along with my script:

text in file:

XXX*XX*     *XX*XXXXXXX.......

here is my kind of what my script looks like (I don't have the script in front of me but you get the jist):

delimiter=$(awk '{substr $0, 4, 1}' file.txt)
echo ${delimiter} # lists files in directory..file.txt file1.txt file2.txt instead of * which is the desired result

Thank you in advance,
Anthony

2 Answers 2

1

Birei is right about your problem. But your AWK expression doesn't seem to be interested in the 1st line only. You can replace it with :

'NR==1 {print substr($0, 4, 1)}'

Then you can do a simple:

echo "$delimiter"
Sign up to request clarification or add additional context in comments.

Comments

0

The shell is interpreting the content of the delimiter variable. You need to quote it to avoid this behaviour:

echo "${delimiter}"

It will print *

1 Comment

I just figured that out this morning and was going to edit my posting....thanks for you response!

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.