0

Working csh script:

#!/bin/csh
foreach xmlfile ( "`cat ~/reportlist.txt`" )
printf $xmlfile"|"
head -c 1000 $xmlfile | awk -F'[="]' '{print $15,"|",$21}'
end

This reads a text file line-by-line and navigates to each file and prints required variables from each file using awk.

I need to perform the same in a bash script. I am new to bash. How can I do this in bash?

1

2 Answers 2

2

The more correct way to do this (see Bash FAQ 001) is

while IFS= read -r xmlfile; do
    printf '%s' "$xmlfile"
    head -c 1000 "$xmlfile" | awk -F'[="]' '{print $15,"|",$21}'
done < ~/reportlist.txt

Using awk to parse XML in this way is fragile, and not recommended. Without seeing the XML in question, though, I cannot recommend a better solution.

Sign up to request clarification or add additional context in comments.

Comments

0

This works:

set +x
for xmlfile in `cat reportlist.txt`
do
printf $xmlfile"|"
head -c 1000 $xmlfile | awk -F'[="]' '{print $15,"|",$21}'
done

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.