For one line of your file:
test='<amar>[amar-1000#Fem$$$_Y](1){india|1000#Fem$$$,mumbai|1000#Mas$$$}'
replace <with a blank character and delete everything after> to get the name
echo $test | sed -e 's/<//g' | sed -e 's/>.*//g'
get all four-digit characters:
echo $test | grep -o '[0-9]\{4\}'
replace the place with your favorite separator
sed -e 's/ /|/g'
This will do:
echo $(echo $test | sed -e 's/<//g' | sed -e 's/>.*//g') $(echo $test | grep -o '[0-9]\{4\}') | sed -e 's/ /|/g'
This will output:
amar | 1000 | 1000 | 1000
with a quick script you got it: your_script.sh input_file output_file
#!/bin/bash IFS=$'\n' #line delimiter #empty your output file cp /dev/null "$2" for i in $(cat "$1"); do newline=`echo $(echo $i | sed -e 's/<//g' | sed -e 's/>.*//g') $(echo $i | grep -o '[0-9]\{4\}') | sed -e 's/ /|/g'` echo $newline >> "$2" done cat "$2"
source share