0

I have the following bash script

counter=0
for file in /home/ec2-user/Workspace/events_parts/*
do
        counter=$[counter + 1]
        event=$(cat $file | jq '.Event')
        echo $event
        if [ "$event" = "Page Exceeded" ]  || [ "$event" = "Reporting Time" ]; then
                echo "Coming Here"
                jq ".url = \"$(jq '.Message' $file | sed 's/.*proxy=\([^&]*\).*/\1/')\"" $file  > events_parts/out_$file
        else
                jq ".url = null" $file > events_parts/out_$file
        fi
done

It does processing of a set of JSON files.I want to redirect it to a filename which has out_$input_file_name. But the variable file prints out the whole path not just the file name (for e.g. /home/ec2-user/Workspace/events_parts/input.json) How do I get just the "input file name" from this?

1

1 Answer 1

1

Try this:

file="/home/ec2-user/Workspace/events_parts/input.json"
filename="$(basename "$file")"
echo "$filename"

Output:

input.json
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.