Swapping of fields in file

Hi Friends ,

I have file1.txt

1|b|46|123|47673|348738
2|c|63|124|7346|4783
3|y|45|125|5555|78789

output should swap the 4th field to the first field.

output

123|1|b|46|47673|348738
124|2|c|63|7346|4783
125|3|y|45|5555|78789

I am newbie to shell . plz help

Try..

awk -F\| '{print $4,$1,$2,$3,$5,$6}' OFS=\| file

@Clx : Thanks for the reply. it works fine. but every line appended with "^M" :frowning: .

i have used

sed 's/^M//g' filename

but it havemt changed any thing .Could you please help on the above issue.

clx's solution should work for you..

and in above command you are trying to remove M which present at the start.
^ indicates start with. ^M will search for lines started with M .
You should add \ to use ^ as a normal character. This might be because of carriage return...

try this..

sed 's/\^M//g' filename