I have a file which I need to parse, word by word, and make changes to only certain words. My bash script works in everything but retaining newline characters. I have constructed a minimum example as follows:
#!/bin/bash
# contents of myscript.sh
toks=( $* )
for tok in ${toks[*]}; do
# make changes to $tok if need be
printf "$tok "
done
I hope to use it as follows:
cat filename.txt | xargs myscript.sh
where filename.txt may look like
word1 word2
word3
The expected output would be the same as input, in this case, but I just get
word1 word2 word3
Try this: