Hi,
Plz help.
input line
1;20100403;400|2;20100403;4|3;20290903;400|4;20290903;0|5;20290903;0|9;20100304;0|10;20100304;0|11;20100402;0|18;20100304;0
expected output
1;20100403;400
2;20100403;4
3;20290903;400
4;20290903;0
5;20290903;0
9;20100304;0
10;20100304;0
11;20100402;0
18;20100304;0
sed -i 's/|/\n/g' file_name
using this we can achieve this.
Consider that the file_name file will contain the content as
1;20100403;400|2;20100403;4|3;20290903;400|4;20290903;0|5;20290903;0|9;20100304;0|10;20100304;0|11;2 0100402;0|18;20100304;0
Now the file will contain the lines as
1;20100403;400
2;20100403;4
3;20290903;400
4;20290903;0
5;20290903;0
9;20100304;0
10;20100304;0
11;2 0100402;0
18;20100304;0
Nila
March 3, 2010, 5:05am
4
You try the following script.
OIFS=$IFS
IFS='|'
for i in `cat inputfile`
do
echo $i
done
IFS=$OIFS
I used OIFS variable in the script to store the old IFS value.Because,if we change it ,we should restore it after our changes.That's why I restored the value at the end of our script.